only the original thread that created a view hierarchy can touch its views解决方案
生活随笔
收集整理的這篇文章主要介紹了
only the original thread that created a view hierarchy can touch its views解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
此錯誤是在非UI線程中更新UI所造成的,解決方案如下:(注:在需要更新UI的地方調用new LongTimeTask().execute("此處為任意字符或空均可");)
private class LongTimeTask extends AsyncTask<String, Void, String> {@Overrideprotected String doInBackground(String... params) {return params[0];}@Overrideprotected void onPostExecute(String result) {//更新UI的操作,這里面的內容是在UI線程里面執行的}}
總結
以上是生活随笔為你收集整理的only the original thread that created a view hierarchy can touch its views解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 号外!2021考研政治肖1000大幅修订
- 下一篇: php owncloud_技术|搭建私有