onloadmore方法在恢复时仅加载5个项目

时间:2015-05-15 10:16:04

标签: android endlessscroll

每次用户完全向下滚动时,应用应加载5个项目, 它工作正常,但当用户更改为另一个活动并返回眉毛活动(主要活动)时,它只加载5个项目

这是我的滚动代码

 recyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
                layoutManager) {
            @Override
            public void onLoadMore(int current_page) {
                int limit = current_page * 5;
                LoadMoreItems(limit);
            }
        });
        return rootView;
    }

加载更多项目方法

private void LoadMoreItems(int limit) {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("product");
        query.setLimit(limit).orderByDescending("createdAt");
        dialog = new ProgressDialog(getActivity());
        dialog.setTitle("Loading");
        dialog.setMessage("Please Wait...");
        dialog.show();
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> scoreList, ParseException e) {
                dialog.dismiss();
                if (e == null) {

                    data.clear();
                    for (int a = 0; a < scoreList.size(); a++) {
                        ParseObject object = scoreList.get(a);
                        ItemsModel model = new ItemsModel();
                        model.setDate(String.valueOf(object.getCreatedAt()
                                .toLocaleString()));
                        model.setPrice(object.getNumber("price").toString() + " R.O");
                        model.setTitle(object.getString("title"));
                        model.setPhone(object.getNumber("phone").toString());
                        model.setDesc(object.getString("desc"));
                        model.setImageFile(object.getParseFile("image")
                                .getUrl());
                        model.setObjectId(object.getObjectId());
                        data.add(model);

                    }
                    adapter.UpdateData(data);

                } else if (e.getCode() == ParseException.CONNECTION_FAILED) {
                    Toast.makeText(getActivity(), "No internet Connection please check your connection!",
                            Toast.LENGTH_LONG).show();

                } else {
                    Toast.makeText(getActivity(),"Error:"+e.getMessage(),
                            Toast.LENGTH_LONG).show();
                }

            }
        });
    }

加载数据方法

private void LoadData() {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("product");
        query.setLimit(5).orderByDescending("createdAt");
        dialog = new ProgressDialog(getActivity());
        dialog.setTitle("Loading");
        dialog.setMessage("Please Wait...");
        dialog.show();
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> scoreList, ParseException e) {
                dialog.dismiss();
                if (e == null) {
                    data.clear();
                    for (int a = 0; a < scoreList.size(); a++) {
                        ParseObject object = scoreList.get(a);
                        ItemsModel model = new ItemsModel();
                        model.setDate(String.valueOf(object.getCreatedAt()
                                .toLocaleString()));

                        model.setPrice(object.getNumber("price").toString() + " R.O");
                        model.setTitle(object.getString("title"));
                        model.setPhone(object.getNumber("phone").toString());
                        model.setDesc(object.getString("desc"));
                        model.setImageFile(object.getParseFile("image")
                                .getUrl());
                        model.setObjectId(object.getObjectId());
                        data.add(model);

                    }
                    adapter = new RecycleViewAdapter(data, getActivity());
                    adapter.setClickListner(BrowseFragment.this);
                    recyclerView.setAdapter(adapter);

                } else if (e.getCode() == ParseException.CONNECTION_FAILED) {
                    Toast.makeText(getActivity(), "No internet Connection please check your connection!",
                            Toast.LENGTH_LONG).show();

                } else {
                    Toast.makeText(getActivity(),"Error:"+e.getMessage(),
                            Toast.LENGTH_LONG).show();
                }

            }
        });
    }

这就是我在onResume

中调用加载数据的方式
 public void onResume() {
        super.onResume();
        LoadData();
    }

0 个答案:

没有答案