RecyclerView element update + async network call

前端 未结 3 995
不知归路
不知归路 2021-02-12 15:22

I have a recyclerview which works as expected. I have a button in the layout that fills the list. The button is supposed to make a async call, and on result, I change the button

3条回答
  •  离开以前
    2021-02-12 15:57

    When the async code is done, you should update the data, not the views. After updating the data, tell the adapter that the data changed. The RecyclerView gets note of this and re-renders your view.
    When working with recycling views (ListView or RecyclerView), you cannot know what item a view is representing. In your case, that view gets recycled before the async work is done and is assigned to a different item of your data.
    So never modify the view. Always modify the data and notify the adapter. bindView should be the place where you treat these cases.

提交回复
热议问题