Remove An Clicked Item From Listview Android
Solution 1:
Just add listview.getAdapter.remove(position); in the OnItemClick method. I suppose you are using an ArrayAdapter though.
EDIT
I'm afraid my explanation was pretty sloppy. The OnItemClick method has 4 arguments: AdapterView l is the ListView whose children are being observed and int position is the child position in the ListView; if (and only if) the list adapter is an ArrayAdapter object, the remove(Object item) method is available and can be used to delete a list item; in order to get the right Object, one must call
Object item = ((ArrayAdapter)l.getAdapter()).getItem(position);
to get the Object to delete; then, the ((ArrayAdapter)l.getAdapter()).remove(item); can be called to remove the selected object.
Solution 2:
You can put string resource into Arraylist, and simply use myArray.remove(position)
method to delete an element in the list view.
Solution 3:
You have 2 options
Remove the item from the list using the remove() method of your ArrayAdapter.
Object toRemove = arrayAdapter.getItem([POSITION]);
arrayAdapter.remove(toRemove);
Or modify the ArrayList and call notifyDataSetChanged().
arrayList.remove([index]);
arrayAdapter.notifyDataSetChanged();
Post a Comment for "Remove An Clicked Item From Listview Android"