简体   繁体   English

我可以删除listView数组但不能更新listview吗?

[英]can i delete array of listView but not update listview?

I spent some time to google it, but didn't help. 我花了一些时间在Google上搜索,但没有帮助。

I have a listview that contains an ArrayList . 我有一个包含ArrayList的列表视图。

Can I collect all data in array, show it in listView and delete array, but not update listView - so data will be on screen? 我可以收集数组中的所有数据,在listView中显示它并删除数组,但不能更新listView-这样数据就会显示在屏幕上吗?

Yes until you scroll the list view to next visible item (or call notify item set change), then ListView ask adapter to provide object for example at 5th position and you will get ArrayIndexOutOfBoundsException or NullPointerException . 是的,直到将列表视图滚动到下一个可见项目(或调用通知项目集更改),然后ListView要求适配器在第5个位置提供对象,例如,您将获得ArrayIndexOutOfBoundsExceptionNullPointerException So if you want to avoid that you have to copy your list elements to another ArrayList instance and pass it to your adapter. 因此,如果要避免这种情况,必须将列表元素复制到另一个ArrayList实例,然后将其传递给适配器。

arrayListMain.get(position).remove(arrayListChild.get(position));
notifydatasetchange();

arrayListMain is which arraylist your are use at setAdapter and arraylistChild is arrayList in your adapter arrayListMain是您在setAdapter上使用的arraylist,而arraylistChild是适配器中的arrayList

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM