0

私は2つのオブジェクトを持っています

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

これはすべきことではないと確信していますが、その方法がわかりません。

4

2 に答える 2

3

最初にそれらを整数に変換する必要があります。

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));
    }
}
于 2012-04-10T15:44:45.827 に答える
0

kailoon のおかげで答えがあります。

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 ));
        }
于 2012-04-11T08:11:02.687 に答える