Android refreshing adapter work after rotation again device

前端 未结 3 1132
[愿得一人]
[愿得一人] 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-18 23:53

    I tried your code and it works just fine with few updates. When you perform this action

     model.add(temp);
     adapter.notifyItemInserted(model.size() - 1);
    

    You are assuming the persistence of the link between the object model and the adapter datasource. This assumption is wrong, in fact if you just replace the code above with

     model.add(temp);
     adapter.setData(model);
     adapter.notifyItemInserted(model.size() - 1);
    

    it works fine. I hope it helped.

提交回复
热议问题