0

I need help for this load more RecycleView, I create 'Recyclerview', first, limit 5 data and showing, but when I scroll until the end no 'ProgressBar' showing and the next data now showing, I check the 'logcat' no error only warning

this my load more function

private void loadMore() {
        arraylist.add(null);
        mListadapter.notifyItemInserted(arraylist.size() - 1);


        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                arraylist.remove(arraylist.size() - 1);
                int scrollPosition = arraylist.size();
                mListadapter.notifyItemRemoved(scrollPosition);
                int currentSize = scrollPosition;
                int nextLimit = currentSize + 5;
                Log.e("currentSize",""+currentSize);
                Log.e("nextLimit",""+nextLimit);
                if(nextLimit <= DataNoteImformation.id.length) {
                    while (currentSize + 1 <= nextLimit) {
                        DataNote wp2 = new DataNote(
                                DataNoteImformation.id[currentSize],
                                DataNoteImformation.branchArray[currentSize],
                                DataNoteImformation.assetcodeArray[currentSize],
                                DataNoteImformation.customerArray[currentSize],
                                DataNoteImformation.licenseplateArray[currentSize]
                        );
                        arraylist.add(wp2);
                        currentSize++;
                    }
                }else {
                    while (currentSize + 1 <= DataNoteImformation.id.length) {
                        DataNote wp2 = new DataNote(
                                DataNoteImformation.id[currentSize],
                                DataNoteImformation.branchArray[currentSize],
                                DataNoteImformation.assetcodeArray[currentSize],
                                DataNoteImformation.customerArray[currentSize],
                                DataNoteImformation.licenseplateArray[currentSize]
                        );
                        arraylist.add(wp2);
                        currentSize++;
                    }
                }
                mListadapter.notifyDataSetChanged();
                isLoading = false;
            }
        }, 2000);


    }

and the warning in logcat

W/RecyclerView: Cannot call this method in a scroll callback. Scroll callbacks might be run during a measure & layout pass where you cannot change theRecyclerView data. Any method call that might change the structure of the RecyclerView or the adapter contents should be postponed to the next frame.

and this example data

public class DataNoteImformation {

    public static String[] branchArray = {"Depok","Jakarta","Bekasi","Jakarta","Jakarta","Bekasi","Bogor","Jakarta","Bekasi","Jakarta"};
    public static String[] assetcodeArray = {"0092","0084","0091","0084","0084","0078","0089","0073","0027","0021"};
    public static String[] customerArray = {"Kevin Sanjaya","Indah Permata","Riyan","Puri Setiawan","Herman","Iwan","Ratna","Agus","Danang","Ujang"};
    public static String[] licenseplateArray = {"B 9829 SK","B 8294 LK","B 9090 NBA","B 7627 SKA","B 7637 SAK","B 6763 KIK","F 7287 NB","F8792KI","B8273KD","B7728KSI"};
    public static String[] id = {"1","2","3","4","5","6","7","8","9","10"};
}

how to fix this.

Ashkan
  • 1,357
  • 4
  • 16
  • 37
D3D
  • 13
  • 5
  • Possible duplicate of [Recyclerview - cannot call this method in a scroll callback](https://stackoverflow.com/questions/42944005/recyclerview-cannot-call-this-method-in-a-scroll-callback) – ADM Apr 19 '19 at 10:07
  • [Use this link](https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview) to implement Pagination . – ADM Apr 19 '19 at 10:08

0 Answers0