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

Source: Internet
Author: User
Tags response code

This article mainly describes how to add a Alertdialog-based dialog box to your application and render the dialog box using Dialogfragment.

    1. You can create a header string resource for the dialog box and add the string str to the Values/strings.xml.
    2. Create a dialogfragment, select Android.support.v4.app.DialogFragment as the base class, and copy the Oncreatedialog method. When the dialogfragment is displayed on the screen, the Fragmentmanager of its hosted activity invokes the replication method to complete the creation of the dialog box. Refer to the following code.
    3. Like other fragment, dialogfragment instances are managed by Fragmentmanager hosting the activity, calling Dialogfragment's Show method: void Android.support.v4.app.DialogFragment.show (Fragmentmanager Manager, String tag); Fragmentmanager parameters for incoming managed activity, The transaction that adds fragment is automatically created and committed.
Public Dialog Oncreatedialog (Bundle savedinstancestate) {//To display dialogfragment on the screen, The Fragmentmanager that hosts the activity calls the method to create a dialog instance/* * Create a Alertdialog instance in a "stream interface": First, by passing in the context object to the Alertdialog.builder class's constructor method * Create a Alertdialog.builder instance, the beginning of new is playing this role; The created Alertdialog.builder instance is tight * Then call the two Alertdialog.builder class's Set Method configuration dialog box (if you need to add a response code for Positivebutton, you need to implement * Dialoginterface.onclicklistener, and replace null), and finally call the Create method of the Alertdialog.builder class for creating the Alertdialog * instance. */return New Alertdialog.builder (Getactivity ()). Settitle (R.string.date_picker_title). Setpositivebutton (Android. R.string.ok, NULL). Create ();}

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

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.