How to delete the checked Items in a multiple choice listview with a contextual action for deletion -
ArrayList<String> liveNames = new ArrayList<String>() {
{
add("dani");
add("john");
add("dave");
add("alen");
add("deno");
add("feliks");
add("jupi");
}
};
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, liveNames);
setListAdapter(adapter);
.......
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
lv = getListView();
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.item1:
if(lv.getCheckedItemCount() > 0){
removeItems = lv.getCheckedItemIds();
deleteSelectedItems(removeItems);
}
mode.finish(); // Action picked, so close the CAB
return true;
default:
return false;
}
}
now how should I implement it in the deleteSelectedItems(long[] delItms) method so that the selected item IDs from the ListView be deleted inside the "names" ArrayList. Please for some hints
I know that I can update the adapters list with
adapter.notifyDataSetChanged();
but how to get the positions of the items inside the listview with their IDs so I could just
name.remove(position) - but I have only the IDs.
Thanks