How to use ProgressDialog with WebView?


Last Updated:

  1. teeming

    teeming Member This Topic's Starter

    Joined:
    Sep 24, 2009
    Messages:
    7
    Likes Received:
    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();

    }
    };

    }
     

    Advertisement

Share This Page

Loading...