First you need a layout interface:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <edittext android:layout_width= "match_parent" android:layout_height= "Wrap_ Content " android:hint=" name "android:id=" @+id/alert_homephone_nameet "/> <edittext android:layout_ Width= "Match_parent" android:layout_margintop= "12DP" android:layout_height= "wrap_content" android:hint= "mobile phone number "Android:id=" @+id/alert_homephone_phoneet " /></linearlayout>
This interface is the interface we need to display when we customize the dialog box.
Alertdialog.builder Builder =new Alertdialog.builder (this); Layoutinflater inflater = Getlayoutinflater (); View layout = inflater.inflate (R.layout.home_phone, null); Builder.setview (layout); Homephonenameet = (EditText) Layout.findviewbyid (r.id.alert_homephone_nameet); Homephoneet = (EditText) Layout.findviewbyid (r.id.alert_homephone_phoneet); Homephoneet.settext ("13195338922"); Homephonenameet.settext ("Lao Wang"); Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {}}); Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () { @Overridepublic void OnClick ( Dialoginterface dialog, int which) {Dialog.dismiss ();} });
Builder.show ();
Note that at the end do not forget show ().
Summary: The method is to customize a layout. It is then populated with Layoutinflater and then specified using the Alertdialog.builder Setview () method. Then call Show () and note the API description of the show () method:
Creates a with the AlertDialog
arguments supplied to this builder Dialog.show()
and ' s the dialog. That is, create a dialog and then display
Android Customization dialog box