我正在开发一款安卓应用。在我的应用中,我需要通过按钮点击来改变一个片段的视图。以下是我的代码:
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中,我该如何做呢?