Android Add layout controls in Alertdialog

Source: Internet
Author: User

Android often needs to have its own control in the pop-up alertdialog, fill in the information, such as pop up a login dialog box

So first you have to create such a layout inputphonenum. XML file.

<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Android:id="@+id/rain_station_list"Android:layout_width="fill_parent"Android:layout_height="fill_parent"Android:background="@drawable/dialog_full_holo_light"android:orientation="Vertical"> <EditText android:layout_width="500DP"Android:layout_height="wrap_content"Android:id="@+id/inputnum"/></linearlayout>

Next, you're going to be quoting this layout in Alertdialog.

The first thing to do is to extract the XML file, which uses the following inflate() function

View view= (LinearLayout) Getlayoutinflater (). Inflate (R.layout.inputphonenum,NULL); Builder Builder=NewAlertdialog.builder ( This); Builder.settitle ("Number Verification"); Builder.setmessage ("Please enter your mobile phone number");                                           Builder.setview (view); //Add this view hereBuilder.setpositivebutton ("Determine",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Inputphonenum= (EditText) View.findviewbyid (r.id.inputnum);//to use the inside of this control, remember to add the view                                        ....                }            }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)            {                    .......                }            }); Builder.create (). Show ();

Android Add layout controls in Alertdialog

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.