美文网首页
RecyclerView 问题记录

RecyclerView 问题记录

作者: Passon_Fang | 来源:发表于2016-04-26 18:04 被阅读12402次

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);
}

相关文章

网友评论

      本文标题:RecyclerView 问题记录

      本文链接:https://www.haomeiwen.com/subject/wwaqrttx.html