通过recycleview的setOnScrollListener监听来控制上拉
得到recycleview的布局管理器,通过布局管理器得到recycleview列表最后一条数据的位置,然后
判断,加载数据
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);
}
}
});