正在加载...列表末尾的行 - 数据下载期间
我有一个充满了互联网数据的列表。
数据以块的形式下载。在列表末尾,下载下一部分数据并将其添加到列表中。
我在 onScrollListner 的帮助下检测列表结尾:
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount) && totalItemCount != mPrevTotalItemCount) {
Log.v(TAG, "onListEnd, extending list");
mPrevTotalItemCount = totalItemCount;
addMoreData();
}
}
我想在下载数据时添加 Loading...
行。类似于列表末尾的 Gmail 加载行。
我知道我可以破解 adapter.getCount()
以返回 size + 1 并强制 adapter.getView
在列表末尾显示加载...。
我怎样才能以更优雅的方式做到这一点?
I have got list that is filled with data from internet.
Datas are downloaded in chunks. At the end of the list next portion of data is downloaded and added to the list.
I'm detecting list end with help of onScrollListner:
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount) && totalItemCount != mPrevTotalItemCount) {
Log.v(TAG, "onListEnd, extending list");
mPrevTotalItemCount = totalItemCount;
addMoreData();
}
}
I would like to addLoading...
row when datas are being downloaded. Something similar to Gmail loading row at the end of the list.
I know that I can hack adapter.getCount()
to return size + 1 and force adapter.getView
to display loading... at the end of the list.
How can I do that in more elegant way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“优雅”就像美丽一样,情人眼里出西施。只有你知道你认为什么是优雅,就像我们只知道我们认为什么是优雅一样,我们各自的定义可能不一致。
FWIW,这是我解决您问题的方法。
"Elegance", like beauty, lies in the eye of the beholder. Only you know what you think is elegant, just as all we know is what we think is elegant, and our respective definitions may not align.
FWIW, here is my approach to your problem.