1. Check out our companion app, Forums for Android! Download from Google Play

How to use ProgressDialog with WebView?

Discussion in 'Application Development' started by teeming, Apr 23, 2010.

  1. teeming

    teeming Member
    Thread Starter
    25

    Sep 24, 2009
    7
    0
    25
    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...