Android - ListView 自动增长未按预期工作
这是我不久前已经问过的问题的延续。有人向我提供了一个解决方案,但它并没有真正起作用。无论如何 - 这是我查看过去的一些帖子的问题/问题
,似乎如果我将项目添加到 ListView 适配器应该自行更新并且用户应该能够 滚动到新添加的项目。不幸的是这不是我的 观察。如果我将新项目附加到现有的 ArrayAdapter 我只会 如果我再次重新运行 ListView#setAdapter,请查看更新的结果。正在做 什么都没有,使视图无效等没有任何作用。这是一个片段:
SearchItemsAdapter a = (SearchItemsAdapter) listview.getAdapter();
List<SearchItem> values = fetchNextSetOfItems();
a.append(values);
// unless I do this - I will not see the update, but if I do -
// I'll jump to the top
listview.setAdapter(a);
这是附加方法:
public void append(List<SearchItem> values) {
this.items.addAll(values);
}
我缺少什么吗?
This is continuation to the question I already asked a while back. I've been offered a solution which is not really working. Anyway - here's the problem/question
I look at some posts from the past and it seems that if I add items to
the ListView adapter it should update itself and user should be able
to scroll to the newly appended items. Unfortunately it's not what I
observe. If I append new items to my existing ArrayAdapter I only will
see updated results if I rerun ListView#setAdapter again. Doing
nothing, invalidating view etc. doesn't do anything. Here's a snippet:
SearchItemsAdapter a = (SearchItemsAdapter) listview.getAdapter();
List<SearchItem> values = fetchNextSetOfItems();
a.append(values);
// unless I do this - I will not see the update, but if I do -
// I'll jump to the top
listview.setAdapter(a);
Here's append method:
public void append(List<SearchItem> values) {
this.items.addAll(values);
}
Anything I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将项目添加到
ArrayList
。将它们添加到ArrayAdapter
。Don't add items to the
ArrayList
. Add them to theArrayAdapter
.