"Turn" Android progressdialog use 2

Source: Internet
Author: User

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

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.