RecyclerView element update + async network call

前端 未结 3 1000
不知归路
不知归路 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:51

    Chet Haase from Google discusses your exact issue in this DevBytes video.

    In short, the framework need to be notified that one of the Views is in "transient" state. Once notified, the framework will not recycle this View until its "transient" flag cleared.

    In your case, before you execute the async action, call setHasTransientState(true) on the child View that should change when the async action completes. This View will not be recycled until you explicitly call setHasTransientState(false) on it.

    Offtopic:

    It looks like you might be manipulating UI elements from background threads. Don't do that! If you can have a reference to Activity then use its runOnUiThread(Runnable action) API instead. If getting a reference to Activity is difficult, you can obtain UI thread's Handler and use its post(Runnable action) API.

提交回复
热议问题