Android refreshing adapter work after rotation again device

前端 未结 3 1133
[愿得一人]
[愿得一人] 2020-12-18 23:09

This code works fine when i add some data into \'List model\' and restore saved data on rotation device, unfortunately after restore data and set that to model

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 00:06

    The main reason is that, because you called set-data and that method did not immediately notify that the data set was changed, therefore it was not ware.
    
          public void setData(List data) {
                Log.e("data size ", data.size() + "");
                list.clear();
                list.addAll(data);
            }
    
         public void setData(List data) {
                Log.e("data size ", data.size() + "");
    
                list.clear();
                notifyDataSetChanged(); //here,to signal change occurred.
                list.addAll(data);
                notifyDataSetChanged(); //here,to signal change occurred.
    
            }
    
    should probably get into the habit of notifying changes on the spot.
    

    The main problem is this, you never notified the changes you made, you cleared it , but you never told it, you know, bu the adapter does not know, also you inserted fresh data with addAll but you still did not notify it.

提交回复
热议问题