본문 바로가기

Mobile/Android

[ Android ] Cannot call this method in a scroll callback

반응형
W/RecyclerView: Cannot call this method in a scroll callback.

 

리싸이클러뷰를 사용하다보면 다음과 같은 메세지를 발견할 수 있다.

스크롤을 할 때마다 뜨는데, 앱이 죽지는 않는다. 

하지만 다음과 같은 메세지는 왜뜰까?

 

Cannot call this method in a scroll callback. Scroll callbacks mightbe run during a measure & layout pass where you cannot change theRecyclerView data. Any method call that might change the structureof the RecyclerView or the adapter contents should be postponed tothe next frame.

 

스크롤 콜백에서이 메서드를 호출 할 수 없습니다. Scroll 콜백은 RecyclerView 데이터를 변경할 수없는 측정 및 레이아웃 단계 중에 실행될 수 있습니다. RecyclerView의 구조 나 어댑터 내용을 변경할 수있는 모든 메서드 호출은 다음 프레임으로 연기되어야합니다.

 

 

쉽게 말하면 리싸이클러뷰가 스크롤 하는 동안

notify 관련 함수(notifyDataSetChanged, notifyItemChanged 등등)를 사용했기 때문이다.

 

해결하기 위해서는 다음과 같이 처리해주면 된다.

 

mRecyclerView.post(new Runnable() {
    public void run() {
        mAdapter.notifyDataSetChanged();
    }
});

 

 

참고 > medium.com/@shahbaz8x/cannot-call-this-method-in-a-scroll-callback-9beaf9abc2db

반응형