BaseRecyclerViewAdapterHelper icon indicating copy to clipboard operation
BaseRecyclerViewAdapterHelper copied to clipboard

BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来;

Open xielihuang opened this issue 4 years ago • 12 comments

public class PostingsCommentAdapter extends BaseQuickAdapter<PostingsCommentModel, BaseViewHolder> {

private final FragmentActivity context;

public PostingsCommentAdapter(FragmentActivity context) {
    super(R.layout.adapter_postings_comment_layout);
    this.context = context;
}
//... UI 展示

}

a. 情况复现: fragment中使用recycleView,添加了两个headerView; 分页加载数据,page = 1,有一个添加数据按钮, 点击把数据添加到adapter中的第一条. 调用addData(int position,T data),没有立即更新UI,需要滑动recycler View才能看到新数据; setNewData也是同样情况~

xielihuang avatar Sep 24 '19 02:09 xielihuang

   if (commentAdapter != null) {
        PostingsCommentModel comment = new PostingsCommentModel();
        comment.setId(id);
        comment.setCreationTime(TimeUtils.getNowString());
        comment.setContent(content);
        comment.setUserSnapshot(UserInfoBiz.getInstance().getUserModel());
        tvCommentCount.setText(("评论数: " + (mTotalCount + 1)));
        commentAdapter.addData(Constants.INDEX_0,comment);
    }

xielihuang avatar Sep 24 '19 02:09 xielihuang

你可以看看你是不是在子线程中调用的,我以前遇到过你说的这个问题。

Go-oG avatar Sep 29 '19 03:09 Go-oG

我也是遇到同样的问题,使用addData(0.list); 然后并不能立即显示,需要手动滑一下才可以。

xingxiang1989 avatar Oct 07 '19 09:10 xingxiang1989

   if (commentAdapter != null) {
        PostingsCommentModel comment = new PostingsCommentModel();
        comment.setId(id);
        comment.setCreationTime(TimeUtils.getNowString());
        comment.setContent(content);
        comment.setUserSnapshot(UserInfoBiz.getInstance().getUserModel());
        tvCommentCount.setText(("评论数: " + (mTotalCount + 1)));
        commentAdapter.addData(Constants.INDEX_0,comment);
    }

你最后有找到解决方法吗

xingxiang1989 avatar Oct 07 '19 10:10 xingxiang1989

这个很好解决的啊,直接在你的添加数据之后加入一个RecyclerView.smoothScrollToPosition(0)就能解决问题了。

lhjgege avatar Oct 17 '19 04:10 lhjgege

1.确保UI线程。 2.更新数据的时候要这样 adapter.setNewData(new ArrayList<>(datas)); 除非你能保证list不是原list。 3.adapter.addData(data);配合dapter.notifyDataSetChanged();使用。

JustinChiang123 avatar Feb 12 '20 13:02 JustinChiang123

可能是调用loadMoreComplete()loadMoreFail()loadMoreEnd() 方法在非UI线程

marvin-an avatar Jul 12 '21 07:07 marvin-an

问题最后解决了么。是怎样处理的。

LiSirWenAn avatar Aug 29 '22 03:08 LiSirWenAn

smartRefreshLayout.computeScroll() smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)

------------------ 原始邮件 ------------------ 发件人: "CymChad/BaseRecyclerViewAdapterHelper" @.>; 发送时间: 2022年8月29日(星期一) 中午11:15 @.>; @.@.>; 主题: Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

问题最后解决了么。是怎样处理的。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

xielihuang avatar Aug 29 '22 03:08 xielihuang

问题最后解决了么。是怎样处理的。

我的问题 是通过在UI线程调用loadXXX()即可。

marvin-an avatar Aug 29 '22 03:08 marvin-an

谢谢回复,有两个问题请教下, smartRefreshLayout.computeScroll() smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)   这样处理的原理是啥啊

另外smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)   最新版本这个 RefreshKernelImpl  这个访问不到。mKernel 是protected 的。搞个子类继承,达到访问目的?

------------------ 原始邮件 ------------------ 发件人: "CymChad/BaseRecyclerViewAdapterHelper" @.>; 发送时间: 2022年8月29日(星期一) 中午11:19 @.>; @.@.>; 主题: Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

smartRefreshLayout.computeScroll() smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "CymChad/BaseRecyclerViewAdapterHelper" @.&gt;; 发送时间:&nbsp;2022年8月29日(星期一) 中午11:15 @.&gt;; @.@.&gt;; 主题:&nbsp;Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

问题最后解决了么。是怎样处理的。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.&gt; — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

LiSirWenAn avatar Aug 29 '22 03:08 LiSirWenAn

我用的核心库2.0.3, 他这个方法大概的意思就是重新测量一下子View的滑动偏移...  我的问题是在smartRefresh里面套了一个recycle, 代码调用recycle滑动到顶部且Foot已经显示的时候出现的. 

------------------ Original ------------------ From: @.>; Send time: Monday, Aug 29, 2022 11:29 AM @.>; @.>; @.>; Subject:  Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

谢谢回复,有两个问题请教下, smartRefreshLayout.computeScroll() smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)&nbsp;&nbsp; 这样处理的原理是啥啊

另外smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)&nbsp; &nbsp;最新版本这个 RefreshKernelImpl&nbsp; 这个访问不到。mKernel 是protected 的。搞个子类继承,达到访问目的?

------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "CymChad/BaseRecyclerViewAdapterHelper" @.&gt;; 发送时间:&nbsp;2022年8月29日(星期一) 中午11:19 @.&gt;; @.@.&gt;; 主题:&nbsp;Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

smartRefreshLayout.computeScroll()
smartRefreshLayout.RefreshKernelImpl().moveSpinner(0, false)

------------------&amp;nbsp;原始邮件&amp;nbsp;------------------
发件人: "CymChad/BaseRecyclerViewAdapterHelper" @.&amp;gt;;
发送时间:&amp;nbsp;2022年8月29日(星期一) 中午11:15
@.
&amp;gt;;
@.@.&amp;gt;;
主题:&amp;nbsp;Re: [CymChad/BaseRecyclerViewAdapterHelper] BaseQuickAdapter addData(position,data)页面没有更新,需要滑动一下才能把新数据展示出来; (#2906)

问题最后解决了么。是怎样处理的。


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: @.&amp;gt;
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.
&gt; — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

xielihuang avatar Aug 29 '22 03:08 xielihuang