Fragment fragment = new Videonew_fragment();
FragmentManager fragmentManager = getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
使用上面的代码转到另一个fragment.i需要传递数据和这个方法。对于数据传递我使用下面的代码它不能正常工作。我做错了什么?帮帮我?
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);
答案 0 :(得分:0)
我不确定您的代码的布局,但您可能遗漏了在打开它时需要将该包添加到特定片段。
//First Create your arguments to pass
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
//Create New Fragment
Fragment fragment = new Videonew_fragment();
//Apply arguments
fragment.setArguments(bundle);
//Now create replace the fragment
FragmentManager fragmentManager = getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();