下拉用的SwipeRefreshLayout
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
adapter = new DangJianRecyclerViewAdapter(this,list);
manager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setAdapter(adapter);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
list.clear();
pageIndex = 1;
loadData(pageIndex+"");
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(newState == RecyclerView.SCROLL_STATE_IDLE){
int lastVisiblePosition = manager.findLastVisibleItemPosition();
if(lastVisiblePosition >= manager.getItemCount() - 1){
pageIndex +=1;
loadData(pageIndex+"");
}
}
}
});
正常速度上拉下拉没什么问题,但是下拉时迅速上拉就会报错