This article mainly describes how to add a Alertdialog-based dialog box to your application and render the dialog box using Dialogfragment.
- You can create a header string resource for the dialog box and add the string str to the Values/strings.xml.
- 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.
- 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)