리사이클러 뷰에 크롤링한 결과 표시하기
android put crawling result into recyclerview
크롤링한 결과를 recyclerview에 표현하고 싶다.
근데 크롤링은 web과 통신을 해서 결과를 받아오는 과정이기 때문에 async, 혹은 핸들러로 처리해야한다.
그런데 item을 새로 추가할 때 변경한 결과를 notifyDataSetChanged 로 반영하려 하면
IllegalStateException 이 뜨고,
Cannot call this method while RecyclerView is computing a layout or scrolling.... 문구가 뜨면서 제대로 나오지 않는다.
참고 -
RecyclerView notifyItemInserted IllegalStateException
i am porting my adapter into RecyclerView.Adapter what i want to achieve: when the user scrolls down near the end i want to start fetch data, i also want to add i ProgressBar view at the end to le...
stackoverflow.com
이럴때는 onPostExecute 내부에서 핸들러를 통해
|
1
2
3
4
5
6
7
8
|
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
};
|
|
변경결과를 갱신해준다.
추가) 만약 checkbox를 recyclerview item에 만들었을때 동일한 문제가 발생한다면 여기를 살펴봐도 좋을 것 같다
Android RecyclerView : notifyDataSetChanged() IllegalStateException
I'm trying to update the items of a recycleview using notifyDataSetChanged(). This is my onBindViewHolder() method in the recycleview adapter. @Override public void onBindViewHolder(ViewHolder
stackoverflow.com

