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

发布于 2024-12-12 04:07:04 字数 274 浏览 0 评论 0原文

当用户滚动到列表视图末尾附近时,我需要加载更多数据。

当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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-12-19 04:07:04

我所做的就是使用 ArrayAdapter 在我的 onCreate 方法中调用 setAdapter 一次。我传入一个 List,我维护对其的引用。当我想添加更多项目时,我将它们添加到此列表中。然后我调用adapter.notifyDataSetChanged

通过这种方式,当用户到达底部时,您可以将更多项目添加到列表末尾,而不是清除 ListView 或设置新的适配器。

What I do is call setAdapter just once, in my onCreate method using an ArrayAdapter. I pass in a List which I maintain a reference to. When I want to add more items, I add them to this list. Then I call 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文