Problem with the Android List View Implementation from Database Records
Thanks a lot for the previous answered questions.Now, I am developing an application having the database implementation. I used the database queries to r开发者_如何学编程etrieve the data from Database but unable to display the retrieved data records as a list of an activity. Please suggest me with the sample code.
1)u need to add data to arraylist and set the arryalistobject to 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));
精彩评论