Android 如何在片段中增加片段

Android 如何在片段中增加片段,android,button,fragment,Android,Button,Fragment,我想用这个按钮来增加上面片段中的片段 请告诉我怎么做。 谢谢你们,朋友们 我的想法是做一个操作界面切换 屏幕五个按钮链接到不同的屏幕 不同的屏幕有五个按钮 这是我的源代码。 备注错误代码 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, save

我想用这个按钮来增加上面片段中的片段

请告诉我怎么做。 谢谢你们,朋友们

我的想法是做一个操作界面切换 屏幕五个按钮链接到不同的屏幕 不同的屏幕有五个按钮

这是我的源代码。 备注错误代码

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.indexomune, container, false);
    Button USER = (Button)view.findViewById(R.id.USER);
    USER.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
                FragmentManager user = getFragmentManager();
                FragmentTransaction User = user.beginTransaction();
                Fragment fragment = user.findFragmentById(R.id.USSER);
                if (fragment == null) {
                    String title = "Fragment A";
                    usermenu TAT = new usermenu(title);
                    user.add(R.id.USSER, TAT);
                    //The method add(int, usermenu) is undefined for the type FragmentManager
                    user.addToBackStack(null);
                    //The method addToBackStack(null) is undefined for the type FragmentManager
                    user.commit();
                    //The method commit() is undefined for the type FragmentManager
                }

        }


    });
    return view;

}

您有两个名为user.的变量。。一个是“用户”,另一个是“用户”。尝试将变量命名为指示变量的名称,这样就不会出现此问题。。比如:FragmentManager FragmentManager=getFragmentManager();问题是你应该使用'User'来添加/addToBackStack/committ谢谢你的帮助我已经知道如何做了首先你必须阅读熟悉的用法,你不能在片段内部增加片段,但你可以在上面的片段中覆盖片段