Android 更改按钮单击时片段的视图

Android 更改按钮单击时片段的视图,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我正在使用Android应用程序。在我的应用程序中,我必须在点击按钮时更改片段的视图。以下是我的代码: public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub if (container == null) { r

我正在使用Android应用程序。在我的应用程序中,我必须在点击按钮时更改片段的视图。以下是我的代码:

public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    if (container == null) {
        return null;
    }
LinearLayout theLayout = (LinearLayout)inflater.inflate(R.layout.settings, container, false);
Button edit = (Button) theLayout.findViewById(R.id.btn_edit);
edit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
// Here I want to change the view.[xml file]
}
        });
return theLayout;

}

在活动中,我们可以使用
setContentView()
更改视图。我怎样才能在片段中做到这一点呢?

我认为最好使用两个片段,并在单击按钮时将一个片段替换为另一个片段。如果您希望以友好方式添加片段-请参见以下示例:

我找到了我问题的答案。事实上,我很愚蠢

edit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                /**
                 * Edit button click will replace Settings screen to
                 * edit screen
                 **/

                theLayout = (LinearLayout)inflater.inflate(R.layout.edit_settings, container, false);


            }
        });

参考这个链接,也看看这个@Saasha…我的我正在使用四个片段,比如tabview。一个片段需要两个视图编辑和保存…如果我单击片段编辑布局的编辑按钮,编辑后如果我单击保存,它将保存,保存按钮将更改为编辑按钮