How to pass data from a fragment to a dialogFragment

后端 未结 4 2174
甜味超标
甜味超标 2020-12-05 07:06

I know that this was asked before, but I dont quite understand how to implement it. I have a fragment \"myFragment\" in which I create an object of a \"myDialogueFragment\".

4条回答
  •  离开以前
    2020-12-05 08:07

    What you need is to setArguments on the fragment as follows:

    Bundle args = new Bundle();
    args.putString("key", "value");
    DialogFragment newFragment = new YourDialogFragment();  
    newFragment.setArguments(args);
    newFragment.show(getSupportFragmentManager(), "TAG");
    

    All you have to do now, is catch those arguments in your fragment and use them...

    AND IN THE DIALOG FRAGMENT YOU READ IT LIKE THIS...

    Bundle mArgs = getArguments();
    String myValue = mArgs.getString("keyUsed to send it...");
    

提交回复
热议问题