【问题标题】:Recycleview pagination not bind adapter androidRecycleview分页不绑定适配器android
【发布时间】:2017-04-14 11:03:44
【问题描述】:

你好朋友我想在我的recycleview中集成分页所以下面是我的代码

在 onCreateVIew 中

  LinearLayoutManager  mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.task_recycle);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(mLayoutManager);
 mRecyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(mLayoutManager) {
            @Override
            public void onLoadMore(int current_page) {
                if (OnzupApplication.mPendingDatas.size() < total) {
                    page++;
                    new getPendingTask(false,true).execute();

                }
            }

        });

if (mAllMethods.check_Internet() == true) {
        new getPendingTask(true,false).execute();
    } else {
        mAllMethods.ShowDialog(getActivity(), "", getString(R.string.net_not_available), "OK");
    }

调用 AsyncTask

    public class getPendingTask extends AsyncTask<Void, Void, Void> {

    private boolean showLoading;
    boolean pagination;

    public getPendingTask(boolean showLoading,boolean page) {
        this.showLoading = showLoading;
        this.pagination=page;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        if (showLoading == true) {
            mProgressDialog = ProgressDialog.show(getActivity(), "", getString(R.string.loading));

        }
    }

    @Override
    protected Void doInBackground(Void... voids) {
        mGetPendigTask = (GetAllPendigTask) mPostParseGet.getPendingTask(mGetPendigTask, token, page);
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        if (showLoading == true) {
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
            }
        }

        try {
            if (mPostParseGet.isNetError) {
                mAllMethods.ShowNoConnectionDialog(mActivity, mContext, "", getString(R.string.net_not_available), getString(R.string.setting), getString(R.string.cancel));
            } else if (mPostParseGet.isOtherError) {
                if (!mPostParseGet.isRequestTimeOutError) {
                    new ActivityHelper(mActivity).sendMail(token);
                }
                mAllMethods.ShowDialog(mActivity, "", getString(R.string.data_not_found), "OK");
            } else {
                if (mGetPendigTask.isSuccess() == true) {
                    mPendingDatas = getData();


                    total = Integer.parseInt(mGetPendigTask.getTotalitems());

                    if (mGetPendigTask.getTasks().size() > 0) {
                        mTextViewNoData.setVisibility(View.GONE);
                        mRecyclerView.setVisibility(View.VISIBLE);
                        mAllPendingRecyclerAdapter = new AllPendingRecyclerAdapter(getActivity(), OnzupApplication.mPendingDatas);
                        if (pagination==false)
                        {
                            mRecyclerView.setAdapter(mAllPendingRecyclerAdapter);
                        }
                        mAllPendingRecyclerAdapter.notifyDataSetChanged();
                    } else {
                        mTextViewNoData.setVisibility(View.VISIBLE);
                        mRecyclerView.setVisibility(View.GONE);
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

当我调用上面的代码时,加载了 1 页,但是当我滚动第二页数据时没有加载任何想法我该如何解决这个问题?

【问题讨论】:

    标签: android pagination android-recyclerview


    【解决方案1】:

    因为这条线

     mAllPendingRecyclerAdapter = new AllPendingRecyclerAdapter(getActivity(), OnzupApplication.mPendingDatas);
    

    当您在 recyclerview 中使用加载更多功能时,您确实创建了适配器。您应该在自己的适配器中添加数据,而不是创建新的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 2017-12-15
      • 1970-01-01
      相关资源
      最近更新 更多