Android Basics of Dialog

Source: Internet
Author: User

There is also a Setview () method in the builder class:

You can add components in a dialog box

Builder.setview (New checkbox (this));//Add checkbox

Builder.setmultichoiceitems (String[]arg0,boolean[]arg1,onmultichoiceclicklistener Arg3)//method of adding a check box

Builder.setsinglechoiceitems (string[]arg0,int arg1,onclicklistener Arg3)//Add a radio box



The code is as follows:

Package com.example.dialog;

Import android.app.Activity;

Import Android.app.AlertDialog.Builder;

Import Android.content.DialogInterface;

Import Android.content.DialogInterface.OnClickListener;

Import Android.content.DialogInterface.OnMultiChoiceClickListener;

Import Android.os.Bundle;


public class Mainactivity extends Activity {

Private builder Builder;

@Override

protected void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.activity_main);

Builder=new Builder (mainactivity.this);

Builder.seticon (Android. R.drawable.ic_dialog_info);

Builder.settitle ("Dialog");

Builder.setmessage ("Dialog dialog box");

Builder.setpositivebutton ("Yes", new Onclicklistener ()

{

public void OnClick (Dialoginterface dialog,int which)

{

}});

Builder.setnegativebutton ("No", New Onclicklistener ()

{

public void OnClick (Dialoginterface dialog,int which)

{

}

}

);

/*builder.setsinglechoiceitems (New string[]{"Radio", "Radio"},1,new Onclicklistener ()

{

public void OnClick (Dialoginterface dialog,int which)

{

}

}

);

*/

/*

Builder.setmultichoiceitems (New string[]{"multi-select", "Multi-select"},new boolean[]{false,true},new onmultichoiceclicklistener ()

{

public void OnClick (Dialoginterface dialog,int which,boolean inchecked)

{

}

}

);*/

/*builder.setitems (New string[]{"list item 1", "List item 2", "list item 3"},new Onclicklistener ()

{

public void OnClick (Dialoginterface dialog,int which)

{

}

}

);*/

Layoutinflater Inflater=getlayoutinflater ();

View layout=inflater.inflate (R.layout.dialog, (ViewGroup) Findviewbyid (r.id.mylayout));

Builder.setview (layout);

Builder.show ();

}

}

You can also add a layout in a dialog box, in addition to adding components.

Add an XML layout file.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/30/89/wKiom1OoPv-yPOVPAAKyZNaLU1A779.jpg "title=" 2014-06-23_224555.png "alt=" Wkiom1oopv-ypovpaakyznalu1a779.jpg "/>

Run as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/30/88/wKioL1OoPxKC4s4rAAEsoxvYLkY307.jpg "title=" 2014-06-23_224747.png "alt=" Wkiol1oopxkc4s4raaesoxvylky307.jpg "/>


This article is from the "Hagar" blog, make sure to keep this source http://7832308.blog.51cto.com/7822308/1429965

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.