How To Delete Item From Listview Using Button?
List_Remind.xml
Solution 1:
As for deleting stuff, you need to delete from the ADAPTER not a list. You don't need to keep your own copy of the items (unless you are using them for something else) because there is a list of item inside the array. you need to call adapter.remove(item)
instead of list.remove(item)
Well you just remove the desired item from the list using the remove() method of your ArrayAdapter
.
A possible way to do that would be:
Object toRemove = arrayAdapter.getItem([POSITION]);
arrayAdapter.remove(toRemove);
Another way would be to modify the ArrayList and call notifyDataSetChanged() on the ArrayAdapter.
arrayList.remove([INDEX]);
arrayAdapter.notifyDataSetChanged();
Solution 2:
Hi try the following code to delete the Item from Listview
Button button1 = (Button) findViewById(R.id.create_message);
button1.setOnClickListener(new OnClickListener()
publicvoidonClick(View v)
{
MyDataObject.remove(positionToRemove);
adapter.notifyDataSetChanged();
}
}
});
Post a Comment for "How To Delete Item From Listview Using Button?"