加载更多RecyclerView错误无法调用此方法

时间:2019-04-19 09:55:22

标签: android android-recyclerview

为此加载更多RecycleView我需要帮助,我创建了'Recyclerview',首先限制了5个数据并显示,但是当我滚动到最后没有显示'ProgressBar'并且现在显示了下一个数据时,我检查了'logcat '没有错误,只有警告

这是我的更多功能

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);


    }

和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.

和本示例数据

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"};
}

如何解决此问题。

0 个答案:

没有答案