public class Progressdialogactivity extends Activity {
Private Button btn_large_pd, BTN_HORIZONTAL_PD;
Declaring a progress bar dialog box
ProgressDialog Mprogressdialog;
Progress
int mCount = 0;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_progressdialog);
BTN_LARGE_PD = (Button) Findviewbyid (R.ID.BTN_LARGE_PD);
BTN_HORIZONTAL_PD = (Button) Findviewbyid (R.ID.BTN_HORIZONTAL_PD);
Set Button Event Listener
Btn_large_pd.setonclicklistener (New Button.onclicklistener () {
@Override
public void OnClick (View v) {
Create a progress bar dialog box Object
Mprogressdialog = new ProgressDialog (
progressdialogactivity.this);
Set the style of the progress bar, the style is round, rotating
Mprogressdialog.Setprogressstyle(Progressdialog.style_spinner);
Set ProgressDialog title
Mprogressdialog.Settitle("Circular Progress bar dialog box Prompt");
Set ProgressDialog prompt information
Mprogressdialog.Setmessage("This is a circular progress bar dialog box.) ");
Set ProgressDialog title icon
Mprogressdialog.SetIcon(R.drawable.ic_launcher);
Sets whether the ProgressDialog progress bar is ambiguous
Mprogressdialog.setindeterminate(false);
Sets whether ProgressDialog can press the bounce key to cancel
Mprogressdialog.setcancelable(true);
Set a button for ProgressDialog
Mprogressdialog.Setbutton("OK",
New Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface dialog, int i) {
Click OK button to cancel the dialog box
Dialog.Cancel();
}
});
Mprogressdialog.Show();
}
});
Btn_horizontal_pd.setonclicklistener (New Button.onclicklistener () {
@Override
public void OnClick (View v) {
MCount = 0;
Create a ProgressDialog object
Mprogressdialog = new ProgressDialog (
Progressdialogactivity.this);
Set the style of the progress bar, the style is the long shape
Mprogressdialog
. Setprogressstyle (Progressdialog.style_horizontal);
Set ProgressDialog title
Mprogressdialog.settitle ("Long-form progress bar dialog box Prompt");
To set ProgressDialog information
Mprogressdialog.setmessage ("This is a long-form progress bar dialog Box! ");
Set ProgressDialog title icon
Mprogressdialog.seticon (R.DRAWABLE.BUTTON31);
Set ProgressDialog progress bar Progress
Mprogressdialog.setprogress(100);
Sets whether the ProgressDialog progress bar is ambiguous
Mprogressdialog.setindeterminate (TRUE);
Sets whether ProgressDialog can be canceled by pressing the return button
Mprogressdialog.setcancelable (TRUE);
Let ProgressDialog show
Mprogressdialog.show ();
New Thread () {
public void Run () {
try {
while (MCount <= 100) {
The progress is controlled by the thread.
Mprogressdialog.setprogress(mcount++);
Thread.Sleep (1000);
}
Mprogressdialog.cancel ();
} catch (Interruptedexception e) {
Mprogressdialog.cancel ();
}
}
}.start ();
}
});
}
}
Android--progressdialog Progress Bar dialog box