RecyclerView 问题记录
2016-04-26 本文已影响12402人
Passon_Fang
RecyclerView 问题记录
1 在点击事件中更新其他项时报错


需要制作子项选择后更新×投票×按钮的颜色的效果。
如果在item点击事件中直接使用notifyDataSetChanged();
来更新界面可能会报下面的错误:
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);
}