问题描述
我有一个的ListView
自定义行。当任何这些行的是点击后,ListView的数据再生。我想该列表滚动回到顶端发生这种情况时。
I have a ListView
with custom rows. When any of these rows isclicked, the ListView's data is regenerated. I'd like the list toscroll 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 tosetSelection is undone. I still don't understand how the ListViewdecides where to scroll to after invalidation, though).
唯一的工作解决方案,我知道被罗曼盖伊这里给出: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)
. Ifound this to perform quite poorly.The newly generated list shows up with its scroll location unchangedand 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的滚动顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!