0

レイアウトに 2 フラグメントを追加するにはどうすればよいですか

1 つのフラグメントを追加できましたが、1 つの画面に 2 つのフラグメントを追加すると、常にエラーが発生します。

これが私が使用したコードです

      Bundle bundle = new Bundle();
      bundle.putString("bussStopCode", bussStopCode);
      bundle.putString("bussStopName", bussStopName);
      Fragment fragment = new FragmentMainClass();
      Fragment fragment2 = new FragmentMainClass();
      fragment.setArguments(bundle);
      FragmentTransaction fragmentManager = getFragmentManager().beginTransaction();
      fragmentManager.replace(R.id.content_frame, fragment);
      fragmentManager.add(fragment2,"lawl");
      fragmentManager.commit();

それらを相対レイアウトに配置したいのですが、方法がわかりません

ここにフラグメントクラスがあります

public static class FragmentMainClass extends Fragment{
    public FragmentMainClass(){}

     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {

         final View rootView = inflater.inflate(R.layout.fragment_searched_data, container, false);
         TextView sn = (TextView) rootView.findViewById(R.id.stop_name);
         TextView sc = (TextView) rootView.findViewById(R.id.stop_code);


         return rootView;
     }


}
4

0 に答える 0