RecyclerView 问题记录

RecyclerView 问题记录

1 在点击事件中更新其他项时报错

RecyclerView 问题记录_第1张图片
RecyclerView 问题记录_第2张图片

需要制作子项选择后更新×投票×按钮的颜色的效果。

如果在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);
}

你可能感兴趣的:(RecyclerView 问题记录)