Hy! I load data from my Db and I will show it in a ListView. Tha problem is that no item is shown. The Listcount is 1. The list gets the data from the db. No error occures. I have no idea why.
Code:
public class Main extends Activity {
private ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = ((ListView)findViewById(R.id.list));
Log.e("XXX List View",lv.toString());
onCreateDBAndDBTabled();
}
private void onCreateDBAndDBTabled() {
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
+ " (_id integer primary key autoincrement, name varchar(100), rate integer(1), eattime datetime)"
+";");
List<String> list = new ArrayList<String>();
Cursor cursor = this.myDB.query(MY_DB_TABLE, new String[] { "name" }, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Log.e("XXX", "Courser Enter: " + cursor.getString(0));
list.add(cursor.getString(0));
} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
Log.e("XXX", "Coung:" + list.size());
ArrayAdapter<String> aa = new ArrayAdapter<String>(Main.this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(aa);
}
}
Log:
09-23 08:49:30.030: ERROR/XXX(6673): Start
09-23 08:49:30.030: ERROR/XXX List View(6673): android.widget.ListView@43d13918
09-23 08:49:30.080: ERROR/XXX(6673): Courser Enter: EditText
09-23 08:49:30.090: ERROR/XXX(6673): Coung:1
Please help
First check your list object is null or not ……… then
http://sudarmuthu.com/blog/using-arrayadapter-and-listview-in-android-applications
http://www.dotnetexpertsforum.com/populate-listview-using-arrayadapter-in-android-t1437.html
https://github.com/sudar/android-samples
also check List list = new ArrayList(); size there are list is empty or not if empty try to get element………….