如何在一个按钮中制作多个活动?我不能,在同一个按钮上做另一个事件。
例如,根据1个radion按钮:
public void onRadioButtonLetterA(View view) {
boolean checked = ((RadioButton) view).isChecked();
if (count == 0) {
// Check which radio button was clicked
switch (view.getId()) {
case R.id.letterA:
if (checked) {
break;
}
default:
break;
}
} else if (count == 1) {
count = 1;
// Check which radio button was clicked
switch (view.getId()) {
case R.id.letterA:
if (checked) {
break;
}
default:
break;
}
}
}
在按钮上:
public void checkButton(View view) {
if (count == 0) {
TextView sumSettlementTextView = (TextView) findViewById(R.id.sumSettlementTextView);
sumSettlementTextView.setText(String.valueOf(sumSettlement));
TextView countTextView = (TextView) findViewById(R.id.countTextView);
countTextView.setText(String.valueOf(count));
}
if (count == 1) {
//Code
}
}
即,如果count == 0
,并单击按钮,并选择了radion按钮,
将确定这样的事情,第二次点击,如果count == 1
,然后单击按钮,并选择radion按钮,
它会做其他事情。
答案 0 :(得分:0)
只需跟踪点击次数
即可int nbClicks = 0;
...
// in your button's onClickListener
if(nbClicks == 0) {
// do something
nbClicks += 1;
} else if (nbClicks == 1){
// do something else
nbClicks += 1;
}
...