Android - Removing Multiple Items From List View
Problem Solved: For anyone in the future who has this problem, I found this this nice tutorial: http://www.androidbegin.com/tutorial/android-delete-multiple-selected-items-listview
Solution 1:
UPDATE:
change your sellList
to contain String
s
private ArrayList<String> sellList;
@Override
publicvoidonItemClick(AdapterView<?> parent, View view,
int position, long id) {
String item = adapter.getItem( position );
if (!sellList.contains( item )) {
listview.setItemChecked(position, true);
view.setBackgroundColor(Color.BLUE);
sellList.add( item );
} else {
listview.setItemChecked(position, false);
view.setBackgroundColor(Color.TRANSPARENT);
sellList.remove( item );
}
}
then
for (String item : sellList) {
adapter.remove( item );
}
sellList.clear();
adapter.notifyDataSetChanged();
listview.clearChoices();
Solution 2:
The list you delete from is not the one the adapter is using. When you pass list
into your adapter it is copied. You need to delete from the list that the adapter is using.
Solution 3:
in onActionItemClicked and switch method:
case R.id.selectAll:
for (int i = 0; i < listView.getAdapter().getCount(); i++) {
customAdapter.selectAll(i);
listView.setItemChecked(i, true);
}
and in the youradapter create:
publicvoidselectAll(int i){
mSelectedItemsIds.put(i, false);
}
Post a Comment for "Android - Removing Multiple Items From List View"