[CymChad/BaseRecyclerViewAdapterHelper]adapter.disableLoadMoreIfNotFullPage()。设置该属性后,不满屏时,不会加载更多。满屏时,上拉到RecylcerView底部,也不会加载更多。

2024-08-08 179 views
5

public class QiuckAdapterSample extends JobBasicActivity { private RefreshAndLoadLayout mRefreshAndLoadLayout; private RecyclerView mRecyclerView; private SilentTask mDataLoaderTask; private Adapter adapter;

@Override
protected void onInitParams(Bundle bundle) {

}

@Override
protected void setupViews(Bundle savedInstanceState) {
    setContentView(R.layout.base_refresh_layout);
    mRefreshAndLoadLayout = (RefreshAndLoadLayout) findViewById(R.id.refresh_load_layout);
    mRefreshAndLoadLayout.initLoadingView(true);
    mRefreshAndLoadLayout.setPullUpEnable(false);
    mRefreshAndLoadLayout.setOnRefreshListener(new RefreshAndLoadLayout.OnRefreshListener() {
        @Override
        public void onPullDownToRefresh() {
            startLoading();
        }

    });
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new Adapter(R.layout.resume_viewed_item,new DataItemResult().getDataList());
    adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
        @Override
        public void onLoadMoreRequested() {
            Log.e("tag","onLoadMoreRequested");
            startLoading();
        }
    });
    adapter.setEnableLoadMore(true);
    adapter.bindToRecyclerView(mRecyclerView);

    adapter.disableLoadMoreIfNotFullPage();

    startLoading();

}

public class Adapter extends BaseQuickAdapter<DataItemDetail,BaseViewHolder>{

    public Adapter(int layoutResId, List<DataItemDetail> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DataItemDetail item) {
        helper.setText(R.id.company_name,item.getString("coname"));
        helper.setImageResource(R.id.tag,item.getBoolean("ismysend") ? R.drawable.resume_viewed_hr_check : R.drawable.resume_viewed_hr_search);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(item.getString("cotypename"))
                .append(getString(R.string.my51job_resumeviewed_item_divide))
                .append(item.getString("cosizename"))
                .append(getString(R.string.my51job_resumeviewed_item_divide))
                .append(item.getString("indtypename"));
        helper.setText(R.id.company_property,stringBuilder.toString());
        helper.setText(R.id.viewed_resume_time,item.getString("viewtime"));
    }
}

public void startLoading(){
    mDataLoaderTask = new SilentTask() {
        @Override
        protected DataItemResult doInBackground(String... params) {
            return 访问接口;
        }

        @Override
        protected void onTaskFinished(DataItemResult result) {
         // 默认给十条数据,可以满屏。
            List<DataItemDetail> list = new ArrayList<>();
            for (int i = 0; i < 5;i++){
                list.addAll(result.getDataList());
            }
            adapter.addData(list);
            mRefreshAndLoadLayout.stopRefresh();
            adapter.loadMoreComplete();
        }
    };

    mDataLoaderTask.executeOnPool();
}

}

回答

2

这个用法好像不对吧

2

@FrankKwok 应该怎么用这个方法呢?我也遇到过这个问题

3

/**

  • check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
  • 不是配置项!!
  • 这个方法是用来检查是否满一屏的,所以只推荐在 {@link #setNewData(List)} 之后使用
  • 原理很简单,先关闭 load more,检查完了再决定是否开启
  • 不是配置项!!
  • @param recyclerView your recyclerView
  • @see #setNewData(List) */
6

@FrankKwok 我是这样设置的,还有个bug,首次进来,满一屏数据之后,下拉刷新,把页面滑到中间,我在onResume的时候,page重置,重新请求数据后,加载更多就没用了

4

page重置什么意思?

7

重新从第一页开始请求数据,setNewData.

5

每次setNewData之后都要调用的

2

@liulance 确实是用法错了,感谢。

8

可不可以求 一个demo。我也出现这样的问题。我放置的setNewData 和disableLoadMoreIfNotFullPage位置不同,先后顺序不同 都回导致。结果显示不同。。好纠结