在 Android ListActivity 中调用 onContentChanged 时如何关闭列表滚动?

发布于 2024-09-07 12:22:23 字数 150 浏览 7 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

烟花肆意 2024-09-14 12:22:23

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., when Activity#setContentView is called. The ListActivity will reinitialize it's content view when it receives onContentChanged.

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 the ListView, most probably by calling notifyDataSetChanged from your Adapter.

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