You can use the getCursor()
method to get the right reference to the Cursor
on which the adapter is based, even after changing it with swapCursor()
. This way you don't need to manually keep/update the reference to the Cursor
.
Dynamically updating ListView with extended SimpleCursorAdapter and Alternate LiteItem Styles
-
19-09-2022 - |
Frage
hi im displaying a ListView with SimpleCursorAdapter
and alternat ListItem
styles, i want to dynamically update the list if the user is on the view and an update occurs. In my ListActivity i have done
adapter.swapCursor(newCursor);
//notify
in my adapter which extends from SimpleCursorAdapter
i have two overridden methods
@Override
public int getViewTypeCount() {
return 2;
}
and
@Override
public int getItemViewType(int position) {
adapCursor.moveToPosition(position);//adapCursor is being set in the constructor
int i= adapCursor.getInt(adapterCursor.getColumnIndexOrThrow("isactive"));
return i==1?i:0;
}
now the problem is when i update the adapter in the activity the updated cursor is not available in getItemViewType
method and hence an index out of bound exception is thrown...
How can i get the updated cursor in it or return proper ItemViewType
Regards
Lösung 2
Andere Tipps
found the solution
just overrided the swapCursor
method
@Override
public Cursor swapCursor(Cursor c){
super.swapCursor(c);
adapCursor=c;
return c;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow