想打一個Android應用程序與主佈局開始,當你按下一個按鈕(稱爲stateButton)即在此佈局的佈局變爲MAIN2佈局包含另一個按鈕(稱爲boton2 ),當你推這一個時,你會回到第一個主體。從一個佈局視圖更改爲另一個並返回?
我想在不創建或啓動另一個活動的同一活動中執行此操作。
在這裏,我向您展示的部分代碼:
public class NuevoshActivity extends Activity
implements SensorEventListener, OnClickListener {
private Button stateButton;
private Button boton2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.stateButton = (Button) this.findViewById(R.id.boton);
this.boton2 = (Button) this.findViewById(R.id.boton2);
stateButton.setOnClickListener(this);
boton2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v==stateButton) {
setContentView(R.layout.main2);
}
else if(v==boton2) {
setContentView(R.layout.main);
}
}
}
的電源只有一些圖像,文本視圖和按鈕。
但我有一些麻煩。難道它不是那麼簡單,或者我錯過了什麼或錯在哪裏?