我有2 Radio Groups
。每个人有2 Radio buttons
。如何获得所选id
的{{1}} radio group
?
答案 0 :(得分:0)
将RadioGroup
添加到RadioGroup
,然后从方法ID
获取所选的onCheckedChanged()
int selectedRadioGroupId = 0;
// Group 1
radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
selectedRadioGroupId = radioGroup.getId();
switch (checkedId) {
case R.id.button1:
// Do something
Toast.makeText(getApplicationContext(), radioButton1.getText() + " clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.button2:
// Do something
Toast.makeText(getApplicationContext(), radioButton2.getText() + " clicked", Toast.LENGTH_SHORT).show();
break;
}
}
});
// Group 2
radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
selectedRadioGroupId = radioGroup.getId();
switch (checkedId) {
case R.id.button3:
// Do something
Toast.makeText(getApplicationContext(), radioButton3.getText() + " clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.button4:
// Do something
Toast.makeText(getApplicationContext(), radioButton4.getText() + " clicked", Toast.LENGTH_SHORT).show();
break;
}
}
});
。
试试这个:
let snapshot: DataSnapshot = self.dataSource.items[indexPath.row]