0

如何在布局中添加 2 片段

我能够添加一个片段,但在一个屏幕中添加 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