更改标志为0和1上的开关按钮然后在Android [英] Change flag to 0 and 1 On button click android
问题描述
当我点击第一次上的一个按钮的背景图像被改变。然后当我点击另一个时间上的按钮它再次得到了冷杉的背景。我已经在全球范围,然后设置一个标志上按一下按钮增量标志计数器。但是当我点击第一次什么也不会发生,但在第二次按钮采取新形象。
期望的:
第1点击:标志变为0:按钮拍摄默认背景。
第二个水龙头:标志变为1:按键采取新的背景。和标志重置为0。
应该是第一抽头0到第二自来水第二抽头1 => 0,第三自来水=> 0复位。
下面是我的code:
标志++;开关(标志){
情况下0:
cbhead.setBackgroundResource(R.drawable.cbxbox);
checkValue1 = TAGN;
的System.out.println(标志折:+ checkValue1);
打破;
情况1:
cbhead.setBackgroundResource(R.drawable.cbxboxchecked);
checkValue1 = TAGN;
的System.out.println(标志上:+ checkValue1);
标志= 0;
打破;
}
只是里面增加的情况下0标志:
标志= 0;
开关(标志){
情况下0:
cbhead.setBackgroundResource(R.drawable.cbxbox);
checkValue1 = TAGN;
的System.out.println(标志折:+ checkValue1);
标志++;
打破;
情况1:
cbhead.setBackgroundResource(R.drawable.cbxboxchecked);
checkValue1 = TAGN;
的System.out.println(标志上:+ checkValue1);
标志= 0;
打破;
}
when i click first time on a button its background image is changed. then when i click another time on the button again it should get its firs background. I have set a flag globally and then on button click increment flag counter. but when i click first time nothing happens but on second time the button take the new image.
desired:
1st click: flag becomes 0: button take default background. 2nd tap: flag becomes 1: button take new background. and flag is reset to 0.
it should be 1st tap 0 to 2nd tap second tap 1 => 0 , 3rd tap=>0 reset.
Here is my code:
flag++;
switch (flag) {
case 0:
cbhead.setBackgroundResource(R.drawable.cbxbox);
checkValue1 = TAGN;
System.out.println("flag off : " + checkValue1);
break;
case 1:
cbhead.setBackgroundResource(R.drawable.cbxboxchecked);
checkValue1 = TAGN;
System.out.println("flag on: " + checkValue1);
flag = 0;
break;
}
Just increment flag inside case 0:
flag=0;
switch (flag) {
case 0:
cbhead.setBackgroundResource(R.drawable.cbxbox);
checkValue1 = TAGN;
System.out.println("flag off : " + checkValue1);
flag++;
break;
case 1:
cbhead.setBackgroundResource(R.drawable.cbxboxchecked);
checkValue1 = TAGN;
System.out.println("flag on: " + checkValue1);
flag = 0;
break;
}
这篇关于更改标志为0和1上的开关按钮然后在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!