How to get data from DialogFragment to a Fragment?

后端 未结 6 1197
独厮守ぢ
独厮守ぢ 2020-11-30 22:13

Imagine, I have FragmentA from which I startDialogFragment (there are EditText in box). How to can I get back the value from the EditTex

6条回答
  •  半阙折子戏
    2020-11-30 22:33

    You need to send the data from the dialog back to the activity via a callback method, then have the activity give that data back to the fragment you want it to go to. Just a quick example:

    public void datFromDialog(String data){
        MyFragment mf = (MyFragment)getFragmentManager().findFragmentById(r.id.frag);
    
        mf.iWantNewData(data);
    }
    

提交回复
热议问题