Original URL: http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420908.html
<?xml version="1.0"encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"android:text="@string/hello"/> <Button android:text="圆形进度条"android:id="@+id/Button01" android:layout_width="wrap_content"android:layout_height="wrap_content"></Button> <Button android:text="长型进度条"android:id="@+id/Button02" android:layout_width="wrap_content"android:layout_height="wrap_content"></Button> </LinearLayout> |
Package com. aina.android;
Import android.app.Activity;
Import Android.app.ProgressDialog;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
public class Test_progressdialog extends Activity {
/** called when the activity is first created. */
Private ProgressDialog Mpdialog;
Private Button btn1,btn2;
private int mCount = 0;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
BTN1 = (Button) This.findviewbyid (R.ID.BUTTON01);
BTN2 = (Button) This.findviewbyid (R.ID.BUTTON02);
Btn1.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Mpdialog = new ProgressDialog (test_progressdialog.this);
Mpdialog.setprogressstyle (Progressdialog.style_spinner);//Set style as a circular progress bar
Mpdialog.settitle ("hint");//Set Caption
Mpdialog.seticon (R.drawable.icon);//Set icon
Mpdialog.setmessage ("This is a circular progress bar");
Mpdialog.setindeterminate (false);//Set whether the progress bar is ambiguous
Mpdialog.setcancelable (TRUE);//Set whether the progress bar can be canceled by pressing the bounce key
Mpdialog.setbutton ("OK", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
Dialog.cancel ();
}
});
Mpdialog.show ();
}
});
Btn2.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
MCount = 0;
Mpdialog = new ProgressDialog (test_progressdialog.this);
Mpdialog.setprogressstyle (progressdialog.style_horizontal);
Mpdialog.settitle ("hint");
Mpdialog.seticon (R.drawable.icon);
Mpdialog.setmessage ("This is a long-form progress bar");
Mpdialog.setmax (100);
Mpdialog.setprogress (0);
Mpdialog.setsecondaryprogress (50);
Mpdialog.setindeterminate (FALSE);
Mpdialog.setcancelable (TRUE);
Mpdialog.setbutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
Dialog.cancel ();
}
});
New Thread () {
public void Run () {
try{
while (mcount<=100) {
Mpdialog.setprogress (mcount++);
Thread.Sleep (100);
}
Mpdialog.cancel ();
}catch (Exception ex) {
Mpdialog.cancel ();
}
}
}.start ();
Mpdialog.show ();
}
});
}
}
"Turn" Android progressdialog use 2