Android Dialogfragment Callback to Fragment

Source: Internet
Author: User

Google has introduced the Fragment concept from 3.0 onwards, using Fragment instead of multiple activity, if you still stay 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,


To take a scene, delete a file, use dialogfragment pop-up user selection, how do you know if the user is determined or canceled, and you do not know when the dialogfragment disappears, because there is no UI event triggered, you do not know to refresh the list,

However, I know that as long as I have a problem, on StackOverflow here can definitely 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 the Fragment. Onactivityresult () can receive a callback, think about it, this is actually a function call, not processed by the system,,,


This example of 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.