Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android从一个输入中减去另一个输入_Android_Textview_User Input - Fatal编程技术网

android从一个输入中减去另一个输入

android从一个输入中减去另一个输入,android,textview,user-input,Android,Textview,User Input,我有两个物体 obj.targetWeight = targetWeight.getText().toString(); obj.currentWeight = currentWeight.getText().toString(); 我想从另一个中减去一个 我试过这个,但运气不好 if (obj != null){ outputEditText.setText("Your target weight is " + obj.targetWeight +

我有两个物体

obj.targetWeight = targetWeight.getText().toString();
obj.currentWeight = currentWeight.getText().toString();
我想从另一个中减去一个

我试过这个,但运气不好

if (obj != null){
    outputEditText.setText("Your target weight is " + obj.targetWeight + 
                            "\n Your current weight is " + obj.currentWeight + "\n" 
                        + (obj.currentWeight - obj.targetWeight));
}

我很确定这不是应该做的,但是我不知道怎么做。

你必须先把它们转换成整数

if (obj != null) {
    int targetWeight = Integer.parseInt(obj.targetWeight.getText().toString());
    int currentWeight = Integer.parseInt(obj.currentWeight.getText().toString());
    outputEditText.setText(
        "Your target weight is " + obj.targetWeight + "\n" + 
        "Your current weight is " + obj.currentWeight + "\n" +
        "Difference is " + (currentWeight - targetWeight));
    }
}

你必须先把它们转换成整数

if (obj != null) {
    int targetWeight = Integer.parseInt(obj.targetWeight.getText().toString());
    int currentWeight = Integer.parseInt(obj.currentWeight.getText().toString());
    outputEditText.setText(
        "Your target weight is " + obj.targetWeight + "\n" + 
        "Your current weight is " + obj.currentWeight + "\n" +
        "Difference is " + (currentWeight - targetWeight));
    }
}

多亏了凯龙,我才有了答案

if (obj != null) {
        int targetWeight = Integer.parseInt(obj.targetWeight);
        int currentWeight = Integer.parseInt(obj.currentWeight);
        outputEditText.setText(
            "Your target weight is " + obj.targetWeight + "\n" + 
            "Your current weight is " + obj.currentWeight + "\n" +
            "Difference is " + (targetWeight - currentWeight ));
        }

多亏了凯龙,我才有了答案

if (obj != null) {
        int targetWeight = Integer.parseInt(obj.targetWeight);
        int currentWeight = Integer.parseInt(obj.currentWeight);
        outputEditText.setText(
            "Your target weight is " + obj.targetWeight + "\n" + 
            "Your current weight is " + obj.currentWeight + "\n" +
            "Difference is " + (targetWeight - currentWeight ));
        }

我添加了代码示例,以显示我输入的代码段应该放在哪里以及如何使用它。如果这仍然不是你想要的,你能更新你的问题,你说它不工作是什么意思吗?嗨。谢谢你的回复。我在“(targetWeight.getText().toString())上遇到以下错误;无法在基元类型int上调用getText()”(同样适用于currentweight)我添加了代码示例,以显示我输入的代码段应该放在哪里以及如何使用它。如果这仍然不是你想要的,你能更新你的问题,你说它不工作是什么意思吗?嗨。谢谢你的回复。我在“(targetWeight.getText().toString())上遇到以下错误;无法在基元类型int上调用getText()”(同样适用于currentweight)请在下次改进您的问题。检查你的拼写和格式。谢谢你的输入,下次请改进你的问题。检查你的拼写和格式。谢谢你的意见