Android Dialogfragment Callback to Fragment

Source: Internet
Author: User

Google has introduced the Fragment concept from the beginning of 3.0, replacing multiple activity with Fragment, assuming you are still in the activity era, then you wall go!


Fragment is good, but a few questions,

1. In the Viewpager, you do not know whether Fragment is currently showing or hiding state, is missing a onshow onhide callback

2. This is the customer problem, showing a dialogfragment callback problem,


For a scene, delete a file. With dialogfragment pop-up user selection, how do you know if the user is determined or canceled, and you do not know when this dialogfragment disappeared, because there is no trigger no matter what UI event, you do not know to refresh the list,

However, I know that only if I have a problem, on StackOverflow here will be able to search the answer


Http://stackoverflow.com/questions/13733304/callback-to-a-fragment-from-a-dialogfragment


That's the problem.


Principle:

Fragment has

@Override
public void Onactivityresult (int requestcode, int resultcode, Intent data)

Callback, when you call getparentfragment () in Fragment. Onactivityresult () can receive a callback, think carefully. This is actually a function call, which has not been processed by the system.


The example on StackOverflow is more reasonable and uses


Dialogfrag.settargetfragment (this, dialog_fragment);
Gettargetfragment (). Onactivityresult (Gettargetrequestcode (), ACTIVITY.RESULT_OK, Getactivity (). GetIntent ());

Combination. More Reasonable

Android Dialogfragment Callback to Fragment

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.