cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

Don't clear data in GridAdapter extend UltimateGridLayoutAdapter #371

Closed billytb closed 8 years ago

billytb commented 8 years ago

Hi There. Please help me fix error

 Process: com.inspius.canyon.yo_video, PID: 3224 
java.lang.NullPointerException: Attempt to invoke virtual method 
'java.lang.String java.lang.Throwable.getMessage()' on a null object reference
at com.marshalchen.ultimaterecyclerview.UltimateViewAdapter.notifyAfterRemoveAllData(UltimateViewAdapter.java:563)
at com.marshalchen.ultimaterecyclerview.UltimateViewAdapter.clearInternal(UltimateViewAdapter.java:461)
at com.marshalchen.ultimaterecyclerview.quickAdapter.easyRegularAdapter.removeAll(easyRegularAdapter.java:215)

My Adapter code ( GridAdapter extend UltimateGridLayoutAdapter ): public void clear() { removeAll(); }

jjhesk commented 8 years ago

tell me the steps to reproduce this

billytb commented 8 years ago

My layout :

    <com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
        android:id="@+id/ultimate_recycler_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:recyclerviewEmptyView="@layout/empty_view"
        app:recyclerviewScrollbars="vertical" />

My Adapter : public class GridVideoAdapter extends UltimateGridLayoutAdapter<VideoModel, GridVideoAdapter.HolderGirdCell> { .... public void clear() { removeAll(); } .... }

My Code :

GridVideoAdapter mAdapter = null;
....
....
public void onInitView() {
        mAdapter = new GridVideoAdapter(new ArrayList<VideoModel>());
        mAdapter.setAdapterActionListener(this);

        mGridLayoutManager = new BasicGridLayoutManager(getContext(), columns, mAdapter);
        ultimateRecyclerView.setLayoutManager(mGridLayoutManager);
        ultimateRecyclerView.setHasFixedSize(true);
        ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                pageNumber = 1;
                requestGetData();
            }
        });
        // setting load more Recycler View
        ultimateRecyclerView.reenableLoadmore();
        ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
            @Override
            public void loadMore(int itemsCount, int maxLastVisiblePosition) {
                requestGetData();
            }
        });

        ultimateRecyclerView.setAdapter(mAdapter);
        requestGetData();
}

    void requestGetData() {
        // check page number
        if (pageNumber < 1)
            pageNumber = 1;

        RPC.requestGetVideoAtHome(type, pageNumber, new APIResponseListener() {
            @Override
            public void onError(String message) {
                stopAnimLoading();
                DialogUtil.showMessageBox(mContext, message);
            }

            @Override
            public void onSuccess(Object results) {
                stopAnimLoading();
                if (ultimateRecyclerView == null)
                    return;
                ultimateRecyclerView.setRefreshing(false);
                // parse data
                List<VideoJSON> listData = (List<VideoJSON>) results;

                // check end data
                if (listData == null || listData.isEmpty())
                    return;

                // check first get data
                if (pageNumber == 1)
                    mAdapter.clear();

                // update data to view
                pageNumber++;
                updateData(listData);
            }
        });
    }
.....
jjhesk commented 8 years ago

i think u have put ultimateRecyclerView.reenableLoadmore(); at the beginning and this is not advised.

billytb commented 8 years ago

sorry, error copy paste, code edited

billytb commented 8 years ago

I still get the same error If i remove "ultimateRecyclerView.reenableLoadmore();", load more dismissed