No error “Only the original thread that created a view hierarchy can touch its views” when the view is updated without delay

前端 未结 1 1519
自闭症患者
自闭症患者 2020-12-20 17:03

I was faced with an interesting problem. If you write the following code in the onCreate/onStart/onResume method of activity:

final Button myBut         


        
相关标签:
1条回答
  • 2020-12-20 18:03

    The check for thread is present only if textView relayout is done. But the Layouting of the view is only done after OnCreate is called . So till the Ui is not shown, changing of textView will not result in invalidating of the view.

    But once the textView has been shown, the UI relayout is required, in which case the thread is checked. So you get the exception only after some time of Oncreate but not immediately.

    0 讨论(0)
提交回复
热议问题