0

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().

4

1 回答 1

2

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.

于 2014-03-19T23:21:32.937 回答