Android progress bar

Source: Internet
Author: User

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/49/51/wKiom1QTCs-zXOFRAABvZvYv35I328.jpg "title=" ch~) fh5dvasax[kz5s0@% ' g.jpg "alt=" Wkiom1qtcs-zxofraabvzvyv35i328.jpg "/>




Package com.malakana.dialog;


Import Android.os.Bundle;

Import Android.os.Handler;

Import Android.os.Message;

Import Android.util.Log;

Import Android.view.View;

Import Android.view.View.OnClickListener;

Import Android.widget.Button;

Import Android.annotation.SuppressLint;

Import android.app.Activity;

Import Android.app.Dialog;

Import Android.app.ProgressDialog;


public class Mainactivity extends Activity {


Final int progress_dialog = 0;

final int increase = 0;

ProgressDialog PD;

Handler HD;


@SuppressLint ("Handlerleak")

@Override

public void OnCreate (Bundle savedinstancestate) {

protected void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.activity_main);


Button bOK = (button) Findviewbyid (R.id.button);

Bok.setonclicklistener (New Onclicklistener () {

@SuppressWarnings ("deprecation")

@Override

public void OnClick (View arg0) {

TODO auto-generated Method Stub

ShowDialog (Progress_dialog); Show dialog box

}


});


Create Handler

HD = new Handler () {

@Override

Overridden methods

public void Handlemessage (Message msg) {

public void Handlermessage (Message msg) {

Calling the parent class

Super.handlemessage (msg);

Determine what information is received

Switch (msg.what) {

The message received is increase

Case Increase:

Progress bar adds 1 each time

Pd.incrementprogressby (1);

Determine if it is greater than 100

if (pd.getprogress () >= 100) {

Pd.dismiss ();

}

Exit

Break

}

}


};

}


Create dialog box

@Override

Public Dialog oncreatedialog (int id) {

Judge ID

Switch (ID) {

Case Progress_dialog:

PD = new ProgressDialog (this);

Set the maximum value

Pd.setmax (100);

Pd.setprogressstyle (progressdialog.style_horizontal);

Set Title

Pd.settitle (R.string.title);

Pd.setcancelable (TRUE);

The Set Progress dialog box cannot be closed with the fallback button

Pd.setcancelable (FALSE);

LOG.D ("KKK", "KKK");

Break

}

return PD;

}


@SuppressWarnings ("deprecation")

@Override

A callback to dynamically update the contents of the dialog box each time a dialog box is popped

public void Onpreparedialog (int id, Dialog Dialog) {

Calling the parent class

Super.onpreparedialog (ID, Dialog);

Switch (ID) {

Case Progress_dialog:

dialog box Progress zeroing

Pd.incrementprogressby (-pd.getprogress ());

New Thread () {

public void Run () {

while (true) {

Hd.sendemptymessage (Increase);

if (pd.getprogress () >= 100) {

Break

}

try {

Thread.Sleep (40);


} catch (Exception e) {

E.printstacktrace ();

}

}

}

}.start ();

Break

}

}

}


Android progress bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.