Trying to refresh a ListView populated by CursorAdapter, I would have thought something like this would work:
SimpleCursorAdapter listAdapter;
@Override
protected void onRestart() {
super.onRestart();
listAdapter.swapCursor(listAdapter.getCursor());
}
In that it swaps cursor from old one to new one and the ListView gets the new data. Why doesn't this way work and what is the alternative?
Slightly more information, swapCursor() is supposed to return the old cursor but in the above it returns null.
EDIT:
I know why it doesn't work. swapCursor() checks if the new cursor and the old cursor are the same, if it is then it does nothing:
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == mCursor) {
return null;
}
And changeCursor calls swapCursor so can't use that. Now to hack that into working...
Aucun commentaire:
Enregistrer un commentaire