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