如何从外部数据库中检索行并在文本视图中显示它们?我尝试了一些代码,但应用程序停止了。
在我的数据库助手中,我添加了该代码:
public String[] getData(String l) {
// TODO Auto-generated method stub
String[] columns = new String[] { DB_ID, DB_name, DB_desc };
// FILTERS DEPENDING ON THE CATEGORY TYPE PASSED IN THE PARAMETER
Cursor c = mDataBase.rawQuery("SELECT _id,name,description FROM facilities WHERE name='" + l + "'", null);
String[] result = new String[] { null, null, null, null, null };
int iId = c.getColumnIndex(DB_ID);
int iName = c.getColumnIndex(DB_name);
int iDesc = c.getColumnIndex(DB_desc);
c.moveToFirst();
result[0] = c.getString(iId);
result[1] = c.getString(iName);
result[2] = c.getString(iDesc);
return result;
}
我希望在 textview 中显示字符串的活动中的这段代码:
for(int i=0;i<4;i++){
// dbhelper.open();
String[] data =dbhelper.getData(namee);
// dbhelper.close();
txt.append("\n"+data[3]+"\n");}
}
这是我尝试过的另一个代码,来自这个 url: Return all data from a SQLite DB into two columns in Android