[問題] Buton OnClick 事件問題
我創了4個xml介面,想分別用4個Button來執行setContentView(R.layout.XXX);
而一開始onCreate(Bundle savedInstanceState) 先執行第一個Xml
程式碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
然後個按鈕的功能:
如果按下butoon1,執行setContentView(R.layout.main);
按下button2,就執行setContentView(R.layout.activity_painting_main2);
按下button3,就執行setContentView(R.layout.activity_painting_main3);等等
我的問題是:
如果按下button2的話,雖然可以執行button2的功能
但是再按下其他button的話,會沒反應
也就是說無法轉移到其他Button所setContentView的畫面...
請問有辦法解決嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.205.97.25
推
10/10 11:26, , 1F
10/10 11:26, 1F
→
10/10 11:26, , 2F
10/10 11:26, 2F
→
10/10 15:15, , 3F
10/10 15:15, 3F
→
10/10 15:16, , 4F
10/10 15:16, 4F
→
10/10 15:47, , 5F
10/10 15:47, 5F
→
10/10 15:47, , 6F
10/10 15:47, 6F
先謝謝各位的回答...
我的xml內都有四個相同id的button我要換的地方,也就是我設4個xml的目的
是要改變畫面中view的部分
xml程式碼:
<view
class="com.example.painting.View1"←這邊是我要切換的地方
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
請問這行Class="xxxxx"有辦法在MainActivity.java內用設定的嗎?
還是有其他方法解決..
可以另外請教bind button的功用嗎 有點不太了解...
再次感謝
※ 編輯: AZHI 來自: 1.168.202.149 (10/11 22:56)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):