点击按钮时更改片段视图

3

我正在开发一款安卓应用。在我的应用中,我需要通过按钮点击来改变一个片段的视图。以下是我的代码:

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中,我该如何做呢?


请参考此链接:http://developer.android.com/reference/android/app/Fragment.html#getView() - Thiru
2个回答

2
我找到了我的问题的答案。实际上是一个非常愚蠢的疑问。
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);


            }
        });

0

也请参考此链接:https://dev59.com/CG025IYBdhLWcg3wl3S- - Saasha
@Saasha... 我正在使用类似TabView的四个片段。一个片段需要两个视图(edit和save)...如果我点击片段的编辑按钮,编辑布局将会出现,编辑完成后,如果我点击保存,则会保存,并且保存按钮将变为编辑按钮。 - sarath

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接