[問題] 如何讓跳轉A B
Button b;
TextView t, t2;
int count, total = 20;
int u_count = 3;
int flag = 1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
t = (TextView) findViewById(R.id.textView1);
while(total>0){
if (flag == 1) {
flag = 0;
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
t.setText("A");
total--;
}
});
} else {
flag = 1;
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
t.setText("B");
total--;
}});}}}}
小弟想要做一個
假如flag =1的時候 按下按鈕會印出A
反之 則印出 B
不知道小弟的CODE有什麼問題...
問過朋友說觀念錯誤>"<
不知道小弟哪裡是錯的...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 113.61.141.108
※ 編輯: closer1018 來自: 113.61.141.108 (10/08 00:24)
→
10/08 00:36, , 1F
10/08 00:36, 1F
→
10/08 00:37, , 2F
10/08 00:37, 2F
total 的用意是...要讓他執行那個總數...
但現在是測試,所以是用20下去代
另外把flag寫在clicklistener裡面這個我有試過
雖然成功但是並不是小弟想要的結果
小弟比較偏向 去判別flag然後有兩個不同的類別
假使flag=1 則執行a()
反之 就執行B()
但先行條件得印得出來@@
所以小弟才這樣測試
※ 編輯: closer1018 來自: 113.61.141.108 (10/08 01:01)
→
10/08 10:13, , 3F
10/08 10:13, 3F
→
10/08 10:13, , 4F
10/08 10:13, 4F
→
10/09 08:36, , 5F
10/09 08:36, 5F
→
10/09 08:37, , 6F
10/09 08:37, 6F