I have a custom Listview using a adapter class to extend ArrayAdapter of a Item class. I have the ability to change between choice modes of NONE,Single and Multi. This all
This is a documented bug, please vote for it:
https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=64596
My use case is the ListView configured as ListView.CHOICE_MODE_SINGLE, I tried @Peter Tran's suggestion without any luck. Here is the workaround that is successful for me:
myAdapter.deleteRow(listView.getCheckedItemPosition());
int checkedIndex = listView.getCheckedItemPosition();
System.out.println("checkedIndex="+checkedIndex);
int count=myAdapter.getCount();
if (checkedIndex==count) listView.setItemChecked(count-1, true);
My test is to manually select the last item on the list(count-1). I omitted the handling for count==0 case but that will most likely be needed. I observed that println() always prints the index of the deleted row. myAdapter.deleteRow() notifies of data change to listeners which says to me ListView isn't properly updating it's checked indices. I've tried this code with hasStableIds() returning both true and false from the custom adapter with the same results.