【问题标题】:how to fix radio button and display the results如何修复单选按钮并显示结果
【发布时间】:2014-05-30 16:44:13
【问题描述】:

您好,我无法修复我的单选按钮我是编码新手,我正在制作一个简单的计算器,但是我不知道如何解决这个问题。

public void onClick(查看 arg0) { // TODO 自动生成的方法存根

            float height=0;
            float age = 0;
            float weight=0;
            float result=0;

            height= Float.parseFloat(h.getText().toString());
            age= Float.parseFloat(a.getText().toString());
            weight= Float.parseFloat(w.getText().toString());

我的问题与 if 语句有关,方程不正确,因为它说它不能识别“*”,如果它们是其他错误,我如何格式化方程以使其在不删除方程的情况下工作如果你也能解决这个问题,我会很高兴的代码谢谢你

            if (male.isChecked())  {

                result = (66.47 + (13.75 * w) + (5.0 * h) - (6.75 * a));

            }

            else if (female.isChecked()){

                result = (665.09 + (9.56 * w) + (1.84 * h) - (4.67*a));

            }


            r.setText(String.valueOf(result));

【问题讨论】:

    标签: android


    【解决方案1】:

    改变

    result = (66.47 + (13.75 * w) + (5.0 * h) - (6.75 * a));
    

    result = (66.47 + (13.75 * weight) + (5.0 * height) - (6.75 * age));
    

    您不能对 wha 应用乘法,因为它们是 Views。

    你需要得到它们的值,然后进行乘法,

    【讨论】:

    • 感谢您的帮助,但我遇到了与此相关的另一个问题,我使用了无线电组而不是普通的单选按钮,我将如何修复代码,因为错误显示在 if 语句中“已检查”
    猜你喜欢
    • 2017-09-30
    • 2015-08-24
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    相关资源
    最近更新 更多