非常感谢以前回答的问题。现在,我正在开发一个具有数据库实现的应用程序。我使用数据库查询从数据库中检索数据,但无法将检索到的数据记录显示为活动列表。请使用示例代码向我建议。
答案 0 :(得分:1)
1)你需要将数据添加到arraylist并将arryalistobject设置为setlistadapter.2) ArrayList results = new ArrayList(); Cursor c = sqLiteDatabase.rawQuery(“SELECT * FROM MY_TABLE”,null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String id = c.getString(c.getColumnIndex("KEY_ID"));
// System.out.println("this is first activity"+firstName);
String firstName = c.getString(c.getColumnIndex("First_Name"));
String lastName = c.getString(c.getColumnIndex("Last_Name"));
//System.out.println("this is first activity====age"+age);
results.add("" + firstName + ",lastName: " + lastName);
}while (c.moveToNext());
}
}
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));