i have a listView
and a button
... when i scroll down on the list .. the button which i named 'scroll_up' appears, so when i click it the list should scroll to the top.. but it didn't until i touch it.. i mean after clicking the button nothing happens ..but if i touch the list it scoll to the top ..
我有一个listView和一个按钮...当我向下滚动列表..我名为'scroll_up'的按钮出现,所以当我点击它时,列表应滚动到顶部..但它没有直到我触摸它...我的意思是在点击按钮后没有任何反应..但如果我触摸列表它scoll到顶部..
here is my button onClick
这是我的按钮onClick
public void scrollup(View v){
lv.smoothScrollToPosition(0);
}
there is no error in the logcat... Note:I use a header in the list .. maybe this what cause the problem .. so is there a way to refresh the layout or somthing similar ?
在logcat中没有错误...注意:我在列表中使用了一个标题..也许这是导致问题的原因..那么有没有办法刷新布局或类似的东西?
2 个解决方案
#1
If you want to move to first index of the list view, use below code:
如果要移动到列表视图的第一个索引,请使用以下代码:
listView.setSelection();
#2
If you want to smooth scroll you may add line in listview in xml
如果要平滑滚动,可以在xml中的listview中添加行
android:smoothScrollbar="true"
or in code:
或在代码中:
lv.setSmoothScrollbarEnabled(true);
And after your code
并在您的代码之后
lv.smoothScrollToPosition(0);
#1
If you want to move to first index of the list view, use below code:
如果要移动到列表视图的第一个索引,请使用以下代码:
listView.setSelection();
#2
If you want to smooth scroll you may add line in listview in xml
如果要平滑滚动,可以在xml中的listview中添加行
android:smoothScrollbar="true"
or in code:
或在代码中:
lv.setSmoothScrollbarEnabled(true);
And after your code
并在您的代码之后
lv.smoothScrollToPosition(0);