问题
I have a DialogFragment
, that depending on how it's called, will either pop up a dialog, or start an Intent, based off of results from the dialogFragment
. Essentially, my DialogFragment
is a list of activities, which depending on how I call I will want more information about the activity, or to start the activity. Ideally, I would like to have something akin to the onActivityResult
to handle these results, in my base class. Doing some research has indicated that if I was using a Fragment, instead of a FragmentActivity
, I could use the DialogFragment.setTargetFragment()
method, but that won't work for a FragmentActivity
. Any other suggestions on what I could do?
回答1:
My solution: Create an interface to receive the data from the Dialog. Pass the appropriate class to the Dialog, and let each function decide what it is going to do.
public interface ListViewDialogReceiver {
abstract void OnListViewDialogReceived(FragmentActivity activity,AbstractItemType itemSelected);
}
Other than that, it's merely creating an appropriate instance of ListViewDialogReceiver, to call the class.
After thinking about this a bit, I could also simplify the interface, assuming that the class is created from the main function. Still, this interface gives me all of the flexibility I might need in the future to handle anything.
来源:https://stackoverflow.com/questions/13755892/results-from-a-dialogfragment-to-an-activityfragment