Android Learning Nine dialog box fragment

Source: Internet
Author: User

The 1.android dialog box is asynchronous and executes the following code as soon as the dialog box is created. Benefits:

A. Feedback the user's interaction with the dialog box by implementing a callback method for the dialog box.   B. Be able to clear the dialog box in the code. 2. The Fragment dialog base class Dialogfragment inherits from fragment. 3 Steps to display a dialog box 2.1 create a dialog Fragment instance 2.2 get the Shard Transaction 2.3 The Show method using the dialog fragment instance shows that the Show method has two versions, the first version receives the Fragmentmanager parameter, The second version receives a fragmenttrancstion parameter. The second version can have the opportunity to add fragmentation transactions to the fallback stack. The first version is more convenient. 3. There are two ways to return the view structure of the dialog fragment, Oncreateview and Oncreatedialog. Oncreatedialog returns a dialog object that can be created by an old-style alertdialog.builder.   4. Clear the dialog fragment there are also two ways to dismiss () and display another dialog box. 4.1 for Dismiss (), it clears from the Shard manager and clears (if any) from the return stack, triggering the callback function Ondissmiss () execution.   However, it is not possible to use Ondismiss to determine that the user button closes the dialog box, and should use OnCancel, which is executed when the user presses the "Back" button. 4.2 For the second method, the code example is as follows: if (someview.getid () = = R.id.btn_invoke_another_dialog)
{
Activity act = getactivity ();
Fragmentmanager fm = Act.getfragmentmanager ();
fragmenttransaction ft = fm.begintransaction ();
Ft.remove (this); //delete current fragment
ft.addtobackstack (NULL); //optional to save the current fragmented transaction anonymously to the return stack, if returned from the new fragment will be displayed again
//null represents no name
for the back stack transaction
helpdialogfragment HDF =
helpdialogfragment.newinstance (R.string.helptext);
hdf.show (ft, "help");
return;

5. Communication between the fragment of the dialog box and the activity

5.1 Activity implements Interface 5.2 dialog fragment calls the interface feedback information of the binding activity. 6. Embedded dialog box 6.1 add container 6.2 to the layout expand the Fragment dialog box to this container.
    

Android Learning Nine dialog box fragment

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.