• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to use ProgressDialog with WebView?

teeming

Lurker
Sep 24, 2009
7
0
Hi,

I am new to android development. I wanted to create an app that
displaying a progressDialog when loading the webpage using
webview.loadurl. However i couldn't make my code run. The app is
loaded with error in the emulator. Below is my code. Hope anybody can
help me trace the problem. Thanks.

package hello.WebView;

import android.app.Activity;
import android.app.ProgressDialog;
import android.view.KeyEvent;
import android.webkit.*;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class HelloWebView extends Activity implements Runnable {

WebView webview;
private ProgressDialog pd;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

pd = ProgressDialog.show(this, "", "Loading...", true,
false);

Thread thread = new Thread(this);
thread.start();

return super.onKeyDown(keyCode, event);
}

public void run() {

webview.loadUrl("http://m.adoimagazine.com");
setContentView(webview);
handler.sendEmptyMessage(0);


}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();

}
};

}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones