在radiogroup中有三個radiobuttons,我使用Java如何實現不同按鈕被選中會發生不同的動作?下面是關於radiogroup和radiobutton的代碼:
final RadioGroup size = (RadioGroup)findViewById(R.id.RGSize);
final RadioButton small = (RadioButton)findViewById(R.id.RBS);
final RadioButton medium = (RadioButton)findViewById(R.id.RBM);
final RadioButton large = (RadioButton)findViewById(R.id.RBL);
if (size.getCheckedRadioButtonId().equals(small){
} else{
}
但是equals不是正確的語法。如何用Java實現按鈕被選中後發生動作的功能?
int selected = size.getCheckedRadioButtonId();
switch(selected){
case R.id.RBS:
break;
case R.id.RBM:
break;
case R.id.RBL:
break;
}