Results from a DialogFragment to an ActivityFragment

只愿长相守 提交于 2019-12-13 04:17:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!