简体   繁体   English

如何将滚动 position 设置到列表视图的顶部

[英]How to set scroll position to top of a listview

I have a listview,I want to refresh it when a button is clicked.My problem is when the scroll postion is at the bottom of listview if I refresh the listview by clearing the adapter, again the scroll position will be at the bottom of the listview.I want the scroll postion to be focused at the top of the listview.我有一个列表视图,我想在单击按钮时刷新它。我的问题是当滚动位置位于列表视图的底部时,如果我通过清除适配器刷新列表视图,滚动条 position 将再次位于列表视图的底部列表视图。我希望滚动位置集中在列表视图的顶部。

尝试使用:

myListView.setSelectionAfterHeaderView();

试试这个,位置为0/1。

yourListView.setSelection(position);

You can try this你可以试试这个

list.smoothScrollToPosition(0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM