1

アプリは、ユーザーが下までスクロールするたびに 5 つのアイテムを読み込む必要があります。正常に動作しますが、ユーザーが別のアクティビティに変更して、brows アクティビティ (メインのアクティビティ) に戻ると、5 つのアイテムしか読み込まれません。

ここにスクロールするための私のコードがあります

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

Load more items メソッド

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();
    }
4

0 に答える 0