通過recycleview的setOnScrollListener監(jiān)聽來控制上拉
得到recycleview的布局管理器,通過布局管理器得到recycleview列表最后一條數(shù)據(jù)的位置,然后
判斷,加載數(shù)據(jù)
private intlastVisibleItemPosition;
//上拉加載
recyclerView.setOnScrollListener(newRecyclerView.OnScrollListener() {
@Override
public voidonScrollStateChanged(RecyclerView recyclerView, intnewState) {
super.onScrollStateChanged(recyclerView,newState);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
lastVisibleItemPosition= ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
if(newState ==RecyclerView.SCROLL_STATE_IDLE&&lastVisibleItemPosition+1==myAdapter_rv.getItemCount()) {
newHandler().postDelayed(newRunnable() {
@Override
public voidrun() {
page++;
presenterNew.getServerData(page);
}
},1000);
}
}
});