我有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));
}
我很确定这不是应该做的,但我无法弄清楚如何去做。
答案 0 :(得分: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));
}
}
答案 1 :(得分:0)
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 ));
}