2012-06-05 144 views
0

我在我的用户界面中有2个编辑框。我想从表中检索数据,并且想要将这些检索到的数据插入到这些编辑文本框中,我如何将数据插入到光标的这些编辑文本框中?从光标检索SQLite查询数据

+0

非常基本的问题谷歌光标它......如果有任何具体问题,请让我们知道... http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/ –

回答

1

检查您的没有。列,它的名字cursor.getColumnCount()cursor.getColumnName(0). respectively.if你列数是2然后光标有两个柱

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