Android Common dialog box

Source: Internet
Author: User

Package com.itheima.dialogs;

Import android.app.Activity;
Import Android.app.AlertDialog;
Import Android.app.ProgressDialog;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Toast;
/*
* Master the first three kinds
*
*/
public class Mainactivity extends Activity {

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
}

Create Confirmation Cancel dialog box
public void Dialog01 (View v) {

Alertdialog.builder Builder = new Alertdialog.builder (this);

Builder.settitle ("Dating ...");
Builder.setmessage ("Say Goodbye to Single, Will you?");

Builder.setpositivebutton ("Willing, GoGoGo", New Dialoginterface.onclicklistener () {

@Override
public void OnClick (Dialoginterface dialog, int which) {
Toast.maketext (Mainactivity.this, "I'm single, maybe I can come to me ...", 0). Show ();
}
});

Builder.setnegativebutton ("unwilling", null);
Builder.show ();
}

Create a Radio dialog box
public void dialog02 (View v) {
Alertdialog.builder Builder = new Alertdialog.builder (this);
Builder.settitle ("Radio dialog Box");
Final string[] items = {"Xiao Li", "Xiao Hong", "Xiao Fang"};
Builder.setsinglechoiceitems (items,-1, New Dialoginterface.onclicklistener () {

@Override
public void OnClick (Dialoginterface dialog, int which) {

Toast.maketext (Mainactivity.this, "was clicked:" + Items[which] + ", Location:" +which, 0). Show ();

}
});
Builder.show ();
}

Create a multi-select dialog box
public void dialog03 (View v) {
Alertdialog.builder Builder = new Alertdialog.builder (this);
Builder.settitle ("multiple selection");
Do not set message here
Builder.setmessage ("Haha, you can choose a number of interested to learn the???");

Final string[] Items ={"Android", "ios", "Java ee", "PHP", "C + +"};
Boolean[] CheckedItems = {True,true,false,false,false};

Builder.setmultichoiceitems (items, CheckedItems, new Dialoginterface.onmultichoiceclicklistener () {

@Override
public void OnClick (Dialoginterface dialog, int which,
Boolean isChecked) {
Toast.maketext ( Mainactivity.this, "was clicked:" + Items[which] + ", Location:" +which+ ", value is:" + isChecked, 0). Show ();
}
});

Builder.show ();

}

//Create progress session
public void dialog04 (View v) {

//A lot of places, doing more time-consuming things will be used when the
ProgressDialog dialog = NE W ProgressDialog (this);
Dialog.setmessage ("desperately loading ....");
Dialog.show ();
//
//try {
//thread.sleep;
Dialog.dismiss ();
//} catch (Interruptedexception e) {
//e.printstacktrace ();
}


//This line of code allows it to be displayed, view the source code, and actually call the above code
//progressdialog.show (This, "message", "desperately loading ..."). Show ();


}

//Create Progress Session box-
public void dialog05 with progress bar (View v) {

ProgressDialog dialog = new ProgressDialog ( this);
Dialog.setmax (100);

//dialog.set

for (int i = 0; i <; i++) {
dialog.setprogress (i);
}
Dialog.show ();

//disappear in seconds
}

}

Android Common dialog box

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.