마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

recyclerview 에서의 SwipeRefreshLayout 사용 문제

0 추천

 

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 가 간헐적으로 먼저 읽히는 현상이 발생하는데 ,, ,

조건 설정을 어떻게 해주는것이 좋을까요 ?

 

status (1,410 포인트) 님이 2017년 3월 28일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...