Question

I can't figure out how my ListView is refreshing itself after deleting an item in onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_item_delete_notification:
            mNotifications.remove(0);
            actionMode.finish();
            return true;
            … 

Obviously I realize the item I am deleting in this code sample is not dynamically chosen, I just put this for example purposes. After deleting an item it will automatically refresh the ListView without me calling notifyDatasetChanged().

Was it helpful?

Solution

ActionMode.finish makes a call to ActionMode.onDestroyActionMode in AbsListView which then calls View.requestLayout. ActionMode.onActionItemClicked will only invoke the action of a MenuItem.

I also notice you're calling mNotifications.remove(0). I don't know if that indicates an ArrayAdapter, but ArrayAdapter.remove makes a call to BaseAdapter.notifyDataSetChanged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top