Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Removing items from a ListView/ArrayAdapter Activity

I have a list (of messages) and I want to give the user the ability to remove these items from the list. I have extended an ArrayAdapter and give it an ArrayList of my messages and would like to simply remove an item from that list and then refresh the ListView instead of reloading the entire list of sent messages. The problem is, if there's only one message and I remove it using listAdapter.remove(messageObject), the adapter is still calling getView() and then throwing NullPointerExceptions all over the place. I'm not sure what the best way is to go about this.

like image 402
MattC Avatar asked Aug 24 '09 01:08

MattC


1 Answers

Apparently things go a little haywire if you don't override the getCount() function in your custom ArrayAdapter. I set it to the size of my ArrayList and now everything seems to be working correctly.

like image 52
MattC Avatar answered Nov 16 '22 05:11

MattC