我有两个片段:(1)Frag1 (2)Frag2。
Frag1
bundl = new Bundle();
bundl.putStringArrayList("elist", eList);
Frag2 dv = new Frag2();
dv.setArguments(bundl);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.the_fragg,dv);
ft.show(getFragmentManager().findFragmentById(R.id.the_fragg));
ft.addToBackStack(null);
ft.commit();
如何在Frag2中获取此数据?
发布于 2011-03-25 06:07:05
您有一个属于Fragment
类的名为getArguments()
的方法。
发布于 2012-08-21 16:14:58
只需在Frag2
的onCreateView()
方法中调用getArguments()
:
public class Frag2 extends Fragment {
public View onCreateView(LayoutInflater inflater,
ViewGroup containerObject,
Bundle savedInstanceState){
//here is your arguments
Bundle bundle=getArguments();
//here is your list array
String[] myStrings=bundle.getStringArray("elist");
}
}
发布于 2017-03-27 14:06:53
在Frag1中:
Bundle b = new Bundle();
b.putStringArray("arrayname that use to retrive in frag2",StringArrayObject);
Frag2.setArguments(b);
在Frag2中:
Bundle b = getArguments();
String[] stringArray = b.getStringArray("arrayname that passed in frag1");
就这么简单。
https://stackoverflow.com/questions/5425568
复制相似问题