I have a layout containing a WebView, and a ProgressBar centred on top of it. The progress bar needs to be shown and hid programatticaly (as web content loads). However, setting the ProgressBar to be visible using loading.setVisibility(View.VISIBLE);, causes a force close. If the ProgressBar is visible by default it works fine. I will paste all appropriate code if needed, but I suspect I’m doing something fundamentally and simply wrong.
(should have force-close tag but neither it nor forceclose exists and I can’t create it.)
Okay, code. The setVisibility is simply:
public void nowLoading() {
loading.setVisibility(View.VISIBLE);
}
nowLoading is called… via javascript, with addJavascriptInterface on the WebView. Ahh… I imagine the WevView is in a different Thread. How do I solve that?
You are probably changing the visibility from the wrong thread. Are you doing the visibility change in a new Thread you started with
Thread.start()?EDIT: use a
Handler(see http://developer.android.com/reference/android/os/Handler.html). Send a Message to the Handler and then do the visibility change from the Handler. Or useView.post(see http://developer.android.com/reference/android/view/View.html#post%28java.lang.Runnable%29).