Java Android浮点到字符串和布局错误

Java Android浮点到字符串和布局错误,java,android,Java,Android,嗨,我正在尝试学习android的Java,但我无法获得最简单的代码。 我正在尝试编写一个百分比计算。代码应该可以工作,但它不允许我将float转换为string totalTextView = (TextView) findViewById(R.id.totalTextView); percentageTxt = (EditText) findViewById(R.id.percentagetxt); numberTxt = (EditText) findViewById(R.

嗨,我正在尝试学习android的Java,但我无法获得最简单的代码。 我正在尝试编写一个百分比计算。代码应该可以工作,但它不允许我将float转换为string

totalTextView = (TextView) findViewById(R.id.totalTextView);
    percentageTxt = (EditText) findViewById(R.id.percentagetxt);
    numberTxt = (EditText) findViewById(R.id.numbertext) ;

Button calcbutton = (Button) findViewById(R.id.calcbutton);
    calcbutton.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View view){
            float percentage = Float.parseFloat(percentageTxt.getText().toString());
            float dec = percentage / 100;
            float total = dec * Float.parseFloat(numberTxt.getText().toString());
        totalTextView.setText(Float.toString(total));
    }
    });

    }
当我尝试用一个额外的变量单独执行时,没有错误,但程序仍然告诉我100的10%是1xd

totalTextView = (TextView) findViewById(R.id.totalTextView);
    percentageTxt = (EditText) findViewById(R.id.percentagetxt);
    numberTxt = (EditText) findViewById(R.id.numbertext) ;

Button calcbutton = (Button) findViewById(R.id.calcbutton);
    calcbutton.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View view){
            float percentage = Float.parseFloat(percentageTxt.getText().toString());
            float dec = percentage / 100;
            float total = dec * Float.parseFloat(numberTxt.getText().toString());
        final String s = Float.toString(total);
                totalTextView.setText(s);
    }
    });

    }
此外,我在格式化元素时遇到问题。拖放不起作用。它们都被堆积起来了。如果我单独输入翻译值,我看不到主内容中一半的元素

!


我知道这是初学者的东西,这可能就是我找不到其他帖子的原因,;)但是我就是想不出来。

试试
String.valueOf(floarValue)
而不是
Float.toString(floatValue)

查看编辑器红色框中的
9+
?您有布局错误。请修复它们假设数学是正确的,请看我很抱歉我没有看到布局错误或9+仔细检查你的图像。“属性”旁边预览窗口的右上角。您正在使用ConstraintLayout,并且尚未将约束应用到视图的右侧。这就解释了为什么你的布局都在设备的左侧哦,好的,谢谢你,我现在看到了,我想所有的错误都会出现在事件日志中XD谢谢你,这很有效,我还注意到,出于某种原因,我的文本视图只有一个didgit。但仍需注意
Float.toString(Float)
不起作用