recyclerview에서 swipeRefreshLayout 사용중일 때에 발생하는 문제인데요,
빠르게 당겨서 리프레시 하는 도중 스크롤을 내리면
간헐적으로 2번째 데이터 그룹부터 가져오는 경우가 발생합니다.
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0) //check for scroll down
{
GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
int lastItem = layoutManager.findLastCompletelyVisibleItemPosition();
int currentTotalCount = layoutManager.getItemCount();
if(currentTotalCount == lastItem + 1 && !isLoading){
isLoading = true;
getGridData();
}
}
}
});
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
isLoading = true;
Adapter.notifyItemRangeRemoved(0, Adapter.getItemCount());
diaryList.clear();
start = 0;
getGridData();
}
});
조건은 마지막 아이템 , 로딩중이지 않으면 다음 그룹을 가져오게 설정하였구요
당겨서 새로고침시에
로딩중, 어댑터 내용 삭제, 어레이리스트삭제, 처음 시작점을 0으로 바꾸고 데이터를 다시 가져옵니다.
근데 로그를 찍어보니 scrollListener 가 간헐적으로 먼저 읽히는 현상이 발생하는데 ,, ,
조건 설정을 어떻게 해주는것이 좋을까요 ?