当ListView没有数据时,OnScrollListener的onScroll无法触发?
当用户滚动到列表视图末尾附近时,我需要加载更多数据。
当ListView的adapter没有数据时,OnScrollListener的onScroll无法触发! 当ListView的setAdapter被调用时,OnScrollListener的onScroll也会被调用。但是当用户推动屏幕并滚动ListView(没有数据)时,OnScrollListener的onScroll尚未被调用。 当ListView至少有一行时,如果用户滚动ListView,OnScrollListener的onScroll将被调用。
I need to load more data when user scrolls to near the end of the listview.
When ListView's adapter has no data, OnScrollListener's onScroll can not be fired!
When the ListView's setAdapter be called, the OnScrollListener's onScroll will be called. But when user push the screen and scroll the ListView(which has no data), the OnScrollListener's onScroll has not been call.
When ListView has at least on row, the OnScrollListener's onScroll will be called if user scroll the listview.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我所做的就是使用
ArrayAdapter
在我的onCreate
方法中调用setAdapter
一次。我传入一个List
,我维护对其的引用。当我想添加更多项目时,我将它们添加到此列表中。然后我调用adapter.notifyDataSetChanged
。通过这种方式,当用户到达底部时,您可以将更多项目添加到列表末尾,而不是清除 ListView 或设置新的适配器。
What I do is call
setAdapter
just once, in myonCreate
method using anArrayAdapter
. I pass in aList
which I maintain a reference to. When I want to add more items, I add them to this list. Then I calladapter.notifyDataSetChanged
.In this manner, you can add more items to the end of your list when the user gets to the bottom, and not clear your ListView or set a new Adapter.