How do I add a view to a conversation?
You can only show an empty dialog box in the previous article, except for the title and a OK button, nothing else, so the dialog box doesn't make any sense. So this article needs to answer questions about how to add content to a dialog box.
Our dialog box was created through Alertdialog.builder and can be followed by a few opportunities to configure the dialog before it is created. To add a view to a dialog box, you can do so by calling Alertdialog.builder's Setview method. First, however, you have to have a view object that can generate a view object in the form of an XML layout file, looking directly at the code (including the following layout file):
PublicDialog Oncreatedialog (Bundle savedinstancestate) {View v=getactivity (). Getlayoutinflater (). Inflate (R.layout.dialog_date,NULL); //to display dialogfragment on the screen, Fragmentmanager, which hosts the activity, calls the method to create a dialog box instance /** Create a Alertdialog instance in the form of a stream interface: first create a Alertdialog.builder instance by passing in the context object to the Alertdialog.builder class, and the beginning of new is playing this role; Create a Alertdialog.builder instance tight * Then call the Set Method Configuration dialog box for the two Alertdialog.builder class (if you need to add a response code for Positivebutton, implement * Dialoginterface *. Onclicklistener, and replace null), and finally call the Create method of the Alertdialog.builder class for creating the Alertdialog * instance. */ return NewAlertdialog.builder (Getactivity ()). Setview (v). Settitle (r.string.date_picker_title). SE Tpositivebutton (Android. R.string.ok,NULL). Create ();}
<?XML version= "1.0" encoding= "Utf-8"?><DatePickerxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/dialog_date_datepicker"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:calendarviewshown= "false" > </DatePicker>
[Android] (Learn note 6) Add a dialog box to the application (2)