The code is as follows:
public class Mainactivity extends Actionbaractivity implements Onclicklistener {
Private Dialog dialog2;
Private Dialog Dialog3;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Button btn= (button) Findviewbyid (R.ID.BTN);
Button btn_first= (button) Findviewbyid (R.id.btn_first);
Button btn_second= (button) Findviewbyid (R.id.btn_second);
Btn.setonclicklistener (this);
Btn_first.setonclicklistener (this);
Btn_second.setonclicklistener (this);
}
@Override
public void OnClick (View arg0) {
Switch (Arg0.getid ()) {
Case R.ID.BTN:
Step through Setting dialog properties
Alertdialog.builder dialog= New Alertdialog.builder (mainactivity.this);
Set Title
Dialog.settitle ("hint message");
Set logo
Dialog.seticon (R.drawable.ic_launcher);
Dialog.setmessage ("This is the cue content!!!") ");
Create () can be omitted, but show () must not be omitted
Dialog.create ();
Dialog.show ();
Break
Case R.id.btn_first:
DIALOG2 = new Alertdialog.builder (mainactivity.this)
Set Title
. settitle ("Delete Files")
Setting dialog box contents
. Setmessage ("Are you sure you want to delete it?" ")
Set icon
. SetIcon (R.drawable.ic_launcher)
Set Confirmation button
. Setpositivebutton ("Confirm", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface arg0, int arg1) {
Toast.maketext (mainactivity.this, "Delete Files", "()." Show ();
}
})
. Setneutralbutton ("info", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface arg0, int arg1) {
Toast.maketext (Mainactivity.this, "details", +). Show ();
}
})
. Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface arg0, int arg1) {
Toast.maketext (mainactivity.this, "Undelete Files", (). Show ();
Dialog2.dismiss ();
}
})
Create () can be omitted, but show () must not be omitted
. Create ();
Dialog2.show ();
Break
Load the Layout dialog
Case R.id.btn_second:
Loading layouts
View view=view.inflate (mainactivity.this, r.layout.content, NULL);
Button btn_confirm = (button) View.findviewbyid (r.id.btn_confirm);
Button btn_cancle = (button) View.findviewbyid (R.id.btn_cancel);
Btn_confirm.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Toast.maketext (mainactivity.this, "login", +). Show ();
If it is alertdialog, there is no dismiss () method; Dialog has a dismiss () method
Dialog3.dismiss ();
}
});
Btn_cancle.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Toast.maketext (Mainactivity.this, "Cancel", +). Show ();
Dialog3.dismiss ();
}
});
Dialog3 = new Alertdialog.builder (mainactivity.this)
. Settitle ("User Login")
. SetIcon (R.drawable.ic_launcher)
. Setview (view)
. Show ();
Break
Default
Break
}
}
This article is from the "Android Development 0 Foundation" blog, please make sure to keep this source http://jinchao.blog.51cto.com/9651275/1588920
Several examples of dialog