Recycleview分页不绑定适配器android

时间:2017-04-12 10:32:27

标签: android pagination android-recyclerview

朋友您好我想在我的循环视图中集成分页,所以下面是我的代码

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页面加载但当我滚动第二页数据没有加载任何想法我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

因为这行

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

当您在recyclerview中使用load more功能时,您第一次创建了适配器。您应该在自己的适配器中添加数据,而不是创建新的