安卓:取下一个ListView / ArrayAdapter活动项目 [英] Android: Removing items from a ListView/ArrayAdapter Activity

查看:115
本文介绍了安卓:取下一个ListView / ArrayAdapter活动项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表(的消息),我想给用户从列表中删除这些项目的能力。我已经延长了 ArrayAdapter ,并给它一个的ArrayList 我的邮件,并想简单地从该名单中删除项目然后刷新重装发送的邮件的整个列表的的ListView 代替。问题是,如果只有一个消息,我删除它使用 listAdapter.remove(messageObject),适配器仍然呼吁 getView(),然后扔 NullPointerException异常所有的地方。我不知道最好的方法就是去了解这一点。

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.

推荐答案

显然,事情有点失控,如果你不覆盖在自定义ArrayAdapter利用getCount()函数。我将其设置为我的ArrayList的大小,现在一切似乎都正常工作。

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.

这篇关于安卓:取下一个ListView / ArrayAdapter活动项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆