**i'm developing an android applicatoin with a webview in it.I need to show a progressbar when the content is loading in the webview.and the progress should be dismissed once the content loading is completed.For the webview part, i use the below code.i use thread.sleep to setJavaScriptEnabled(true) because i setJavaScriptEnabled(false) at first and after 15 sec setJavaScriptEnabled(true).what should i do
public class Activity1 extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);
Toast.makeText(getApplicationContext(), "welcome", Toast.LENGTH_LONG).show();
String url = "http://student.iaun.ac.ir";
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new myWebViewClient());
webView.getSettings().setJavaScriptEnabled(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(url);
webView.getSettings().setSavePassword(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
startDelay();
webView.getSettings().setJavaScriptEnabled(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
void startDelay() throws InterruptedException {
Thread.sleep(15000);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity1, menu);
return true;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}