0
我有一個回收視圖,我想在用戶到達recycleview結束時運行asynTask。這是我的代碼:android - 如何回收視圖只有滾動下來才能運行任務
recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recycle.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (loadmore) {
if (totalItemCount > previousTotal) {
loadmore = false;
previousTotal = totalItemCount;
}
}
if (!loadmore && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
if(taskrunning!=null && taskrunning==false){
loadmore = false;
page = page + 1;
new AsyncHttpTask().execute(url);
}
}
}
});
它的工作原理髮現,當我到達recycleView結束,但是當我scrollup,它再次調用的AsyncTask。
我不想在我滾動時調用asyncTask,我只想向下滾動時調用它。
我該怎麼辦?