2012-06-05 5 views
0

내 UI에 2 개의 편집 상자가 있습니다. 테이블에서 데이터를 가져 오려고하고 검색된 데이터를 편집 텍스트 상자에 삽입하려면 어떻게해야합니까? 데이터를 커서의 편집 텍스트 상자에 삽입 할 수 있습니까?SQLite 쿼리 데이터를 커서에서 검색

+0

아주 기본적인 질문 구글을 사용하여 커서를 닫고있다 ... 특정 문제가 있다면 알려주십시오. http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/ –

답변

1

귀하의 번호를 확인하십시오. 열 및 2 다음 커서 당신의 열 수 respectively.if 이름 cursor.getColumnCount()cursor.getColumnName(0). 두 개의 열 데이터베이스에서 데이터를 가져 오는 완료 후

cursor.moveToFirst(); 

String columnName1 = cursor.getColumnName(0); 
String columnName2 = cursor.getColumnName(1);  

String str1 = cursor.getString(cursor.getColumnIndex(columnName1))); 
String str2 = cursor.getString(cursor.getColumnIndex(columnName2))); 

editext1.seText(str1); 
editext2.seText(str2); 

cursor.close();

0
// Activity.onCreate function 

EditText etfirstname= (EditText)findViewById(R.id.firstname); 
EditText etlastname= (EditText)findViewById(R.id.lastname); 
MyDatabase database = new MyDatabase(this); 

Cursor c = database.queryRaw("SELECT firstname, lastname FROM users WHERE id=1"); // query data from database 
if(c.moveToFirst()){ 
    etfirstname.setText(c.getString(0)); // read firstname 
    etlastname.setText(c.getString(1)); // read lastname 
} 

c.close(); // dont forget to close cursor! 
+0

도움이 되었으면 녹색을 클릭하는 것을 잊지 마십시오. 내 대답 옆에있는 기호를 확인하십시오! :) – papaiatis