如何在两个子片段之间传递数据从父ParentFragment延伸?

时间:2017-12-02 10:31:16

标签: java android

我有两个“Child”片段和一个“Parent”片段,所以如何在“Child”片段之间传递数据? 谢谢大家!!

1 个答案:

答案 0 :(得分:0)

Create newInstance() of ClidFragment and set the arguments--

public static ClidFragment newInstance(String arg1, String agr2) {
        ClidFragment fragment = new ClidFragment();
        Bundle args = new Bundle();
        args.putString(Key_arg1, arg1);
        args.putString(Key_arg2, arg2);
        fragment.setArguments(args);
        return fragment;
    }

Receive arguments in ClidFragment Fragment--
(Write this code in on create)
            Bundle args = getArguments();
            String arg1 = args.getString(Key_arg1);
            String arg2 = args.getString(Key_arg2);

SetArgument form Parent Fragment --
When you are replacing fragment then set The argument like this-
ClidFragment childFragment= ClidFragment.newInstant(arg1,arg2);
then replace your fragment using childFagment.

//Hope this help you