简体   繁体   English

当ListView没有数据时,无法触发OnScrollListener的onScroll吗?

[英]When ListView has no data, OnScrollListener's onScroll can not be fired?

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! 当ListView的适配器没有数据时,无法触发OnScrollListener的onScroll! When the ListView's setAdapter be called, the OnScrollListener's onScroll will be called. 调用ListView的setAdapter时,将调用OnScrollListener的onScroll。 But when user push the screen and scroll the ListView(which has no data), the OnScrollListener's onScroll has not been call. 但是,当用户按下屏幕并滚动ListView(无数据)时,尚未调用OnScrollListener的onScroll。 When ListView has at least on row, the OnScrollListener's onScroll will be called if user scroll the listview. 当ListView至少具有一行时,如果用户滚动listview,则将调用OnScrollListener的onScroll。

What I do is call setAdapter just once, in my onCreate method using an ArrayAdapter . 我要做的是使用ArrayAdapter在我的onCreate方法中仅调用一次setAdapter I pass in a List which I maintain a reference to. 我传递了一个List ,供我参考。 When I want to add more items, I add them to this list. 当我想添加更多项目时,我将它们添加到此列表中。 Then I call adapter.notifyDataSetChanged . 然后,我调用adapter.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. 这样,您可以在用户到达底部时将更多项目添加到列表的末尾,而不必清除ListView或设置新的Adapter。

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

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