[Android] (Learn note 6) Add a dialog box to the application (2)

Source: Internet
Author: User
Tags response code

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)

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.