Fragment1与Fragment2有一个不同的父级,实际上我想与他的父级一起访问Fragment2。
Fragment2 fragment = new Fragment2().getParentFragment();
fragment.setArguments(bundle);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.containerView,fragment);
ft.commit();
答案 0 :(得分:0)
您必须按意图将数据传递给secondActivity,然后使用setData方法将数据传递给片段。注意,您必须在片段的onCreateView函数中执行此操作。像下面的代码:
public void setData(Data data){
this.data = data;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View rootView = inflater.inflate(R.layout.fragment_layout,container,false);
// use data here
// also use view components(like buttons) here
return rootView;
}