开发者

Problem using ProgressBar.setProgress(int)

开发者 https://www.devze.com 2023-03-28 22:39 出处:网络
08-18 11:24:09.503: ERROR/AndroidRuntime(22649): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarch开发者_开发问答y can touch its vi

08-18 11:24:09.503: ERROR/AndroidRuntime(22649): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarch开发者_开发问答y can touch its views.

Is there any solution? :/


Yes. You can't touch UI in non-UI threads, so the solution is to run the problematic code inside a runOnUiThread:

runOnUiThread(new Runnable() {
    public void run() {
        //your problematic code
    }
});


Only the UI thread can manipulate with views and stuffs. If you are working in another thread, try using Handler to post change to view to UI thread or switch to use AsyncTask

So you are using AsyncTask already, so you should ProgressBar.setProgress() inside onProgressUpdate() of AsyncTask. Override this method

0

精彩评论

暂无评论...
验证码 换一张
取 消