I need to make an infinite scroll. In the examples with the listview , I have an adapter.notifyDataSetChanged(); . But here in the RecyclerAdapter for some reason does not want.

Help me please.

 cardview.addOnScrollListener(new EndlessRecyclerViewScrollListener((LinearLayoutManager) mLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount) { new GetListData().execute(); mAdapter.notifyDataSetChanged(); } }); 

    3 answers 3

    You and for ListView should not work. You call notifyDataSetChanged too soon before the task is completed. And when the data comes, the list will not be updated.

    You need to call notifyDataSetChanged in onPostExecute your task.

      As a result, such a construction helped (submitted for execution after data loading):

       mAdapter = new RecyclerAdapter(newData); cardview.swapAdapter(mAdapter,false); 

        It is impossible to call such methods while the internal mechanism RecyclerView is working. Update need for some events. For example, we received a response from the network, or from Loader. As a crutch will help:

         cardview.post(new Runnable() { mAdapter.notifyDataSetChanged(); }); 

        In this case, the method will execute outside the Recycler method and nothing will "break."