Android: Removing items from a ListView/ArrayAdapter Activity

一曲冷凌霜 提交于 2019-12-05 00:43:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1320108/android-removing-items-from-a-listview-arrayadapter-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!