点击按钮改变一个 fragment 视图

我想通过点击按钮来改变一个fragment视图

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;

}

在 activity 中可以使用setContentView() 改变视图
如何在 fragment 中实现呢?

很简单的解决方案:

  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);

                }
            });

bt = getFragmentManager().beginTraition();
bt.add() 或者 bt.replace()
最后Commit