【问题标题】:Radiobutton behavior Android Studio单选按钮行为 Android Studio
【发布时间】:2015-04-12 03:27:03
【问题描述】:

解决的简单问题(我希望)......但我自己无法解决。 当检查/选中另一个时,我需要一个无线电按钮才能未经检查或未选择。

这是我的代码。现在应用程序运行良好,但是当用户更改选择时,第一个按钮不清除:

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();
            }
        }
    }

});

【问题讨论】:

    标签: java android radio-button


    【解决方案1】:

    您只需将 RadioButtons 分组到 RadioGroup
    这就是您获取mutually exclusive RadioButtons 所需的全部内容。

    供您参考:http://developer.android.com/guide/topics/ui/controls/radiobutton.html

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      相关资源
      最近更新 更多