Several examples of dialog

Source: Internet
Author: User

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

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.