大家好我在我的应用程序中有listview但滚动到底部后再次设置为第一个位置。
listView = (ListView) findViewById(R.id.list);
start = listView.getFirstVisiblePosition();
listView.setSelectionFromTop(start, 0);
删除以下代码后,它工作正常,但滚动后setOnItemClickListener不起作用。
listView.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE )
{
listView.invalidateViews();
}
}
@Override
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {}
});
任何建议将不胜感激。提前致谢
答案 0 :(得分:0)
请尝试这种方式,希望这有助于您解决问题。
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int lastInScreen = firstVisibleItem + visibleItemCount;
if((lastInScreen == totalItemCount)){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
listView.smoothScrollToPosition(0);
}
},1000); // change (1000) value as per your requirement like : when list shown last item then after 1 second list scrolled to 0 position
}
}
});