Android adds a radio button "define dialog" in dialog

Source: Internet
Author: User



XML file:

Create a Click button and add a click Method:


<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:orientation= "vertical"    tools:context= ". Mainactivity ">    <button        android:id=" @+id/button1 "        android:layout_width=" Fill_parent        " android:layout_height= "Wrap_content"        android:onclick= "Showalertdialog"        android:text= "AlertDialog"/ ></LinearLayout>





Mainactivity: Implementation of Click Button Monitoring method


public void Showalertdialog (view view) {/* * Set Radio items * */alertdialog.builder Builder = new Alertdialog.builder (mainactiv Ity.this);//internal Use builder's design mode final string[] items = {"Apple", "orange", "Banana"};builder.settitle ("Dialog"); Builder.setsinglechoiceitems (items, -1,new Onclicklistener () {///The second parameter is set by default which item is selected-1 means no @overridepublic void is selected by default OnClick (dialoginterface dialog, int which) {//TODO auto-generated method Stubtoast.maketext (Mainactivity.this, items[ which], 0). Show ();}}); Builder.setcancelable (false);///Settings dialog can only be exited by clicking the button on the dialog, unable to exit the close Dialogbuilder.create () by a fallback button. Show (); /Create Object}


Android adds a radio button "define dialog" in dialog

Related Article

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.