Android的ListView的滚动顶部 [英] Android ListView scrolling to top

查看:89
本文介绍了Android的ListView的滚动顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ListView 自定义行。当任何这些行的是 点击后,ListView的数据再生。我想该列表 滚动回到顶端发生这种情况时。

I have a ListView with custom rows. When any of these rows is clicked, the ListView's data is regenerated. I'd like the list to scroll back to the top when this happens.

我用最初尝试 setSelection(0)中的每一行的 OnClickListener 要实现这一点,但没有成功(我相信,因为的ListView 失去了它,当它的数据是无效的滚动位置 - 所以我的呼吁 setSelection是百废待兴。我还是不明白是怎么的ListView 确定在何处滚动到失效后,虽然)。

I initially tried using setSelection(0) in each row's OnClickListener to achieve this but was unsuccessful (I believe because the ListView loses its scroll position when its data is invalidated - so my call to setSelection is undone. I still don't understand how the ListView decides where to scroll to after invalidation, though).

唯一的工作解决方案,我知道被罗曼盖伊这里给出: <一href="http://groups.google.com/group/android-developers/browse_thread/thread/127ca57414035301">http://groups.google.com/group/android-developers/browse_thread/thread/127ca57414035301

The only working solution I know of was given by Romain Guy here: http://groups.google.com/group/android-developers/browse_thread/thread/127ca57414035301

它涉及( View.post )荷兰国际集团在调用 _listView.setSelection(0)。一世 发现这表现相当不佳。 新生成的列表显示了它的滚动的位置不变 并有一个相当大的延迟之前它滚动回顶端。

It involves (View.post)ing the call to _listView.setSelection(0). I found this to perform quite poorly. The newly generated list shows up with its scroll location unchanged and there is a considerable delay before it scrolls back to the top.

有没有什么更好的方法来实现这个功能?

Is there any better way to achieve this functionality?

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

谢谢!

推荐答案

呼叫 listView.setSelectionAfterHeaderView(); 滚动到顶部

这篇关于Android的ListView的滚动顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆