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