RecyclerView 問題記錄
1 在點(diǎn)擊事件中更新其他項(xiàng)時(shí)報(bào)錯(cuò)
需要制作子項(xiàng)選擇后更新×投票×按鈕的顏色的效果。
如果在item點(diǎn)擊事件中直接使用notifyDataSetChanged();
來更新界面可能會(huì)報(bào)下面的錯(cuò)誤:
java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
解決方案:
private void specialUpdate() {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
notifyItemChanged(getItemCount() - 1);
}
};
handler.post(r);
}