因此,我查看了其他问题,但无法提出解决方案。所以基本上,我有一个父片段和一个子片段,我需要将一个整数传递给子片段。子片段在XML中定义,因此,据我所知,我无法附加捆绑包。看起来应该很简单,但我无法弄清楚。
任何有关如何执行此操作的帮助都将非常有用。谢谢!
一个简单的解决方案是在您的父片段onCreateView上获得对您的子片段的引用
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.parent_fragment, container, false);
YourChildFragment fragment = (YourChildFragment) getChildFragmentManager().findFragmentById(R.id.child_fragment_id);
// pass your data
fragment.setMyInt(42);
return view;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句