我想在 ListView 中设置一个简单的侦听器,以便当用户通过列表的 50° 项目时,我调用一个线程,将另外 100 个项目追加到该列表中。
我正在寻找一个活动来执行此操作一个多小时,但我似乎找不到。有大量关于何时单击列表项或类似事件的事件,但我找不到当用户简单地在滚动处理中传递该项目时的事件。
提前非常感谢!
I want to set a simple listener in a ListView so when the user passes through the 50º item of the list, I call a thread that will append 100 more items into that list.
I am looking for an event to do that for over an hour now and I don't seem to be able to find one. There are tons of events for when a list item will be clicked or something like that, but I can't find one for when the user simples passes through the item in the scroll processing.
Thank you so much in advance!
发布评论
评论(2)
将 ScrollListener 放在列表视图上,当它到达列表末尾时,您将获得最后一个项目,然后在页脚添加进度条,然后启动线程,您可以在其中加载其他项目,并为适配器提供 notificationDataSetChanged() ,您将获取添加项目的列表..!!
您可以在 onScroll() 中检查项目编号是否达到 50。
Put the ScrollListener on list view, when it reaches end of the list u will get the last item, then add the progressbar at the footer and then start thread where u can load the other items, and notifyDataSetChanged() for adapter , and you will get the list with added items..!!
And you can check whether the item number 50 is reached, in onScroll().
我认为没有必要这样做,因为
ListView
回收了项目视图。因此,您不会占用列表视图项(每个值)的内存,只需将内存用于 ArrayList(或用于提供的任何数据类型)。此外,每当用户到达列表视图的末尾(最后一个列表视图项)时,您都可以执行此操作,然后使用新值重新输入适配器,然后调用
.notifyDataSetChanged()
。大约达到 listview 可见项目的 50% 可能会让事情变得混乱,因为你总是会达到 50%,否则你可以通过检查是否显示超过 50% 的现有 ArrayList 来即兴发挥(在 ArrayList 而不是 ListView 上达到 50%) ,假设您有 10 个项目,第 6 个项目位于列表视图计数 / 2 上,您检查那一半列表视图项目是否超过数据源的 50%对于您提供新数据的列表视图。 (可能我说的不太清楚)
希望这个想法对你有帮助。
I think there is no need to do this, because the
ListView
recycles the item views. So you dont occupy memory for the listview items (per each value), you just use memory for theArrayList
(or any data type you use for feeding).Also you can do this whenever user reaches the end of the listview (last listview item) then refeed the adapter with the new value and then call
.notifyDataSetChanged()
.About reaching 50% of listview visible items can make things scrambled because you'll always have the 50% reached, otherwise you can improvise (reaching 50% on the ArrayList instead ListView) by checking if more than 50% of the existing ArrayList is displayed, let's say you 10 items and the 6th item is on the listview count / 2, you check if the on that half listview item is more than 50% of data feed for the listview you feed with new data. (I might be unclear)
I hope the idea will help you.