How to update RecyclerView Adapter Data?

前端 未结 13 2332
误落风尘
误落风尘 2020-11-22 03:48

Trying to figure out what is the issue with updating RecyclerView\'s Adapter.

After I get a new List of products, I tried to:

  1. Update t

13条回答
  •  悲&欢浪女
    2020-11-22 04:27

    I've solved the same problem in a different way. I don't have data I waiting for it from the background thread so start with an emty list.

            mAdapter = new ModelAdapter(getContext(),new ArrayList());
       // then when i get data
    
            mAdapter.update(response.getModelList());
      //  and update is in my adapter
    
            public void update(ArrayList modelList){
                adapterModelList.clear(); 
                for (Product model: modelList) {
                    adapterModelList.add(model); 
                }
               mAdapter.notifyDataSetChanged();
            }
    

    That's it.

提交回复
热议问题