修复的简单问题(我希望)...虽然无法弄明白。 当选中/选择另一个时,我需要一个单选按钮被取消选中或取消选中。
这是我的代码。现在应用程序工作正常,但当用户去更改选择时,第一个按钮不会清除:
Button convert = (Button) findViewById(R.id.btnConvert);
convert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
weightEntered=Double.parseDouble(weight.getText().toString());
DecimalFormat tenth = new DecimalFormat("#.#");
if (lbToKilo.isChecked()) {
if (weightEntered <= 500) {
convertedWeight = weightEntered / conversionRate;
result.setText(tenth.format(convertedWeight) + " kilograms");
} else {
Toast.makeText(getApplicationContext(), "Pounds must be less than 500.", Toast.LENGTH_LONG).show();
}
}
if (kiloToLb.isChecked()) {
if (weightEntered <= 225) {
convertedWeight = weightEntered * conversionRate;
result.setText(tenth.format(convertedWeight) + " pounds");
} else {
Toast.makeText(getApplicationContext(), "Kilos must be less than 225.", Toast.LENGTH_LONG).show();
}
}
}
});
答案 0 :(得分:1)
您只需将您的RadioButton分组到RadioGroup
这就是获得一些mutually exclusive
RadioButtons所需的一切。
供参考:http://developer.android.com/guide/topics/ui/controls/radiobutton.html