Android 修改textview的变量
我想做一个游戏,当用户发送错误的输入时,他会得到更少的尝试。上面的代码打印初始编号,但我只想修改变量,不想像这样更新:Android 修改textview的变量,android,Android,我想做一个游戏,当用户发送错误的输入时,他会得到更少的尝试。上面的代码打印初始编号,但我只想修改变量,不想像这样更新: int triesno=5; final TextView tries= (TextView) findViewById(R.id.tries); tries.setText("you have "+triesno.toString()+" tries left"); 我该怎么做?你确定你的问题吗 triesno--; tries.setText("you have "+tr
int triesno=5;
final TextView tries= (TextView) findViewById(R.id.tries);
tries.setText("you have "+triesno.toString()+" tries left");
我该怎么做?你确定你的问题吗
triesno--;
tries.setText("you have "+triesno.toString()+" tries left");
清楚你在问什么吗?我不想写文本,我只想修改变量。修改什么变量?tries.toString()我只想更新textview的那部分,而不是整个文本。他有两个同名变量。最初,textview将设置为trys.setText(“你有”+triesno.toString()+“trys left”);我问是否有一种方法可以不写tries.setText(“您有”--triesno+“tries left”);稍后再说。是的,这就是我要找的。非常感谢。
final TextView tvTries = (TextView) findViewById(R.id.tries);
int tries = Integer.parseInt(tvTries.getText()); // Get current number of time that you can try to.
tvTries .setText("you have "+ --tries + " tries left"); // -1 and set to textview
int tries = 5;
final TextView triesTv = (TextView) findViewById(R.id.tries);
tries = tries - 1;
String triesStr = String.format("you have: %d tries left", tries);
triesTv.setText(triesStr);