我有两个“Child”片段和一个“Parent”片段,所以如何在“Child”片段之间传递数据? 谢谢大家!!
答案 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