Baserecyclerviewadapterhelper: 上拉加载问题

Created on 13 Dec 2017  ·  3Comments  ·  Source: CymChad/BaseRecyclerViewAdapterHelper

你好,为什么这么写刚开始就会一次性地把所有的数据都加载完?不知道哪里出问题了。

@Override

public void loadMoreComment(List<Comment> commentList, boolean loadMoreEnd) {
    if (mAdapter == null) {
        mAdapter = new CommentAdapter(this, R.layout.item_postinfo_comment, commentList);
        mAdapter.setPreLoadNumber(1);
        mAdapter.setOnLoadMoreListener(this, mCommentRecyclerView);
        mAdapter.setOnItemClickListener(this);
        mCommentRecyclerView.setAdapter(mAdapter);
    } else {
        mAdapter.addData(commentList);
        mAdapter.loadMoreComplete();
    }
    if (loadMoreEnd) {
        mAdapter.loadMoreEnd();
    }
}

@Override

public void onLoadMoreRequested() {
    LogUtils.e("onLoadMoreRequested");
    mPresenter.requestMoreComment(mPost.getId(), ++page);
}

Most helpful comment

已发现问题的原因,recyclerview嵌套在NestedScrollView里面会导致上拉加载失效,一次性加载出全部数据,求大佬解决!

All 3 comments

已发现问题的原因,recyclerview嵌套在NestedScrollView里面会导致上拉加载失效,一次性加载出全部数据,求大佬解决!

ScrollView嵌套会有机制上的冲突,ScrollView会去提前测量高度。正好加载更多的原理就是最后一个可见item作为除非条件,这样会导致无限加载,这样有2个办法,1.将嵌套部分的布局当作头部和尾部添加到rv上面或下面,去除ScrollView。2.更换第三发的嵌套的上拉下拉控件。

我也遇到同样的问题,但是recyclerview如果不嵌套在NestedScrollView里的话,向上滑动时toolbar就不能实现那种悬停在顶部的效果(看了大半天源码,原来问题在这,但是作者的两种解决方法基本不能采取,求更牛解决方法????)

Was this page helpful?
0 / 5 - 0 ratings