这个应用是一个16组单选按钮步进应用程序,每组有8个按钮。除了一组按钮被选中后,我不能将其关闭,除非使用我创建的清除按钮清除所有的单选按钮组。我想添加的代码是当再次选择已选中的单选按钮时,它就像切换开关一样被关闭。我尝试使用切换开关,但是那种方法会导致其他问题。下面是我的一次尝试,但是我猜测它偏离了正确方向。
final RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.RadioGroup1);
RadioButton lC1 = (RadioButton)findViewById(R.id.RadioButtonlowC1);
Button D1 = (Button)findViewById(R.id.RadioButtonD1);
D1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PdBase.sendFloat("D1", 74);
int selectedTypeId = radioGroup1.getCheckedRadioButtonId();
RadioButton D1 = (RadioButton) findViewById(selectedTypeId);
if(radioGroup1 != null) // This will be null if none of the radio buttons are selected
radioGroup1.clearCheck();
PdBase.sendFloat("D1", 0);
}
});