Dynamic SQLite ListView onUpdate greys out all items
I have an Activity which goes through the normal procedures.
databaseHelper = new AppDatabaseHelper(this ); //openOrCreateDatabase(Constants.NAME, 1, null);
database = databaseHelper.getWritableDatabase();
// select columns[] from table order by sentdate desc
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");
// Does the displaying work //
cursorAdapter = new SimpleCursorAdapter(this, R.layout.mail_element, cursor, col开发者_C百科umns, columnsMap);
lv.setAdapter( cursorAdapter );
My problem is when the list gets refreshed, the dataset observer does not fire, and executing this code from a timer to ensure it is working causes all elements in the listview to become greyed out, or 50ish% invisible.
Log.d(Constants.TAG, "MailActivity > List changed!");
CursorAdapter.notifyDataSetChanged();
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");;
cursorAdapter = new SimpleCursorAdapter(context, R.layout.mail_element, cursor, columns, columnsMap);
lv.setAdapter( cursorAdapter );
Does anyone have an idea why these elements are turning grey when the list is updated? When I exit the activity and re-open it, it shows up fine again.
Solved, I had to change the cursor, instead of re-doing the adapter!
Log.d(Constants.TAG, "MailActivity > List changed!");
cursorAdapter.notifyDataSetChanged();
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");;
cursorAdapter.changeCursor( cursor );
lv.setAdapter( cursorAdapter );
精彩评论