我正在使用web視圖的進度條。我需要在頁面加載之前停止進度條。按下後退按鈕但在加載之間不工作。如何在使用後退按鈕加載之前關閉進度條?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
progressBar =new ProgressDialog(this);
progressBar.setCancelable(true);
progressBar.show();
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("TEST", "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e("TEST", "Error: " + description);
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
mWebView.loadUrl("http://www.google.com");
}
對於後退按鈕測試我使用這個
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
Toast.makeText(getApplicationContext(),"hi", Toast.LENGTH_LONG).show();
return true;
}
return super.onKeyDown(keyCode, event);
}
我已經實現了代碼使用AsnyTask和簡單的處理程序也有同樣的問題,有沒有其他的想法?像我如何殺死堆棧中的任何活動? – 2011-02-11 07:40:16
沒有必要,只是檢查我的答案 – 2011-02-11 10:22:30