有没有更简单的方法来做到这一点?简单的方法来处理字符串数字?
int score = Integer.parseInt(tv_score.getText());
score += 100;
tv_score.setText(String.valueOf(score));
有没有更简单的方法来做到这一点?简单的方法来处理字符串数字?
int score = Integer.parseInt(tv_score.getText());
score += 100;
tv_score.setText(String.valueOf(score));
是的,有你的原始对象数据类型的更简单的方法,而不是原始数据类型
Integer score = new Integer(tv_score.getText());
score += 100;
tv_score.setText(score.toString());
,或者您也可以像这样,使之更短,精确
Integer score = new Integer(tv_score.getText())+100;
tv_score.setText(score.toString());
不要使用'new Integer()'。 'Integer.valueOf()'。 – QBrute
int score = Integer.parseInt(tv_score.getText());
如果在文本字段或textarea中输入的数字不是十进制格式,这将不起作用。
If the number will always be in decimal format, then use
- int x = Integer.parseInt("11") + 10;
And for an instance, if the number is in hexadecimal format, then use
- int x = Integer.parseInt("1B", 16) + 10;
希望这会有所帮助。 :-)
你可以做''“+分数' – QBrute
将分数保留在类字段中,并且不要从TextView中获得分数。 –
java强制类型,你得和它一起生活:( – nafas