handler
-
[Android] Do not treat position as fixed; only use immediately and call viewHolder.getAdapterPosition() to look it up later 에러 발생Android 2022. 10. 25. 15:13
발생 : Do not treat position as fixed; only use immediately and call viewHolder.getAdapterPosition() to look it up later 발생상황 recyclerview adapter에서 onBindViewHolder 메소드중 handler 를 구현하여 handlerMessage 내부에서 position 값을 사용하니 발생 원인 position 값이 달라질수 있다는 경고 해결 viewHolder가 가지고 있는 position 값을 이용 absoluteAdapterPosition 호출하여 사용함
-
[android] Only the original thread that created a view hierarchy can touch its views. 에러 발생Android 2022. 10. 25. 15:07
에러코드 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 발생상황 recyclerview 를 통해 adapter 를 연결하고 adapter내에서 TimerTask를 생성하여 Timer 스케쥴을 등록함. 원인 Main Thread 외의 새로 생성한 Thread를 이용하여 UI를 변경하려 하면 Exception을 발생시킨다. 해결방법으로는 Handler 생성하여 handler 메세지 구현하여 메세지 호출