我想通過點擊按鈕來改變一個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);
}
});