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