lundi 12 janvier 2015

Can't Get Android ListView Working Properly

I'm try to make a ListView for my app, but there's an error (java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list') which i can't resolve, this problem appear when i successfully put the listview working but it won't updated after add or remove data mysq sqlite database.


My listview code;



MessageRepo repo = new MessageRepo(this);
msgsList = repo.getMessageList();
lv = getListView();
ArrayAdapter<HashMap<String, String>> arrayAdapter = new ArrayAdapter<HashMap<String, String>>(this,android.R.layout.simple_list_item_1, msgsList);
setListAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();//my second problem


getMessageList() code:



public ArrayList<HashMap<String, String>> getMessageList() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
String selectQuery = "SELECT " +
Message.KEY_ID + "," +
Message.KEY_message +
" FROM " + Message.TABLE;

//Message Message = new Message();
ArrayList<HashMap<String, String>> MessageList = new ArrayList<HashMap<String, String>>();


Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list

if (cursor.moveToFirst()) {
do {
HashMap<String, String> Messagehash = new HashMap<String, String>();
Messagehash.put("id", cursor.getString(cursor.getColumnIndex(Message.KEY_ID)));
Messagehash.put("message", cursor.getString(cursor.getColumnIndex(Message.KEY_message)));
MessageList.add(Messagehash);

} while (cursor.moveToNext());
}

cursor.close();
db.close();
return MessageList;

}


Listview xml code:



<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire