在 Android ListActivity 中调用 onContentChanged 时如何关闭列表滚动?
我有一个ListActivity。
我使用 onContentChanged() API 更新活动。
我的问题是,每次调用上述 API 时,列表都会滚动到顶部。有什么简单的方法可以关闭这个“功能”吗?
谢谢。
/ 亨里克
I got a ListActivity.
I update the activity using onContentChanged() API.
My problem is that each time I call the above API the list scrolls to the top. Is there any easy way to turn this "feature" off?
Thanks.
/ Henrik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Activity#onContentChanged
不适用于“更新”活动的数据。当活动的内容视图发生变化时,即当Activity#setContentView
被调用时,它被调用。ListActivity
将在收到onContentChanged
时重新初始化其内容视图。答案是,你做错了,不要按照你现在的方式使用
onContentChanged
。这就是您看到这种意外行为的原因。使用另一种方法来更新ListView
,最有可能的方法是从Adapter
调用notifyDataSetChanged
。Activity#onContentChanged
is not for 'updating' the data for the activity. It is called when the content view of the activity changes, i.e., whenActivity#setContentView
is called. TheListActivity
will reinitialize it's content view when it receivesonContentChanged
.The answer is, you're doing it wrong, don't use
onContentChanged
the way you are using it. That is why you are seeing this unexpected behavior. Use another method to update theListView
, most probably by callingnotifyDataSetChanged
from yourAdapter
.