我正在使用一堆 boolean 值,根据这些 boolean 值的结果将一个整数值设置为一定数量。这段代码工作正常。我提供的代码的第一行是显示“completedtotal”和“total”的正确值。但是当我将文本添加到按钮时,它会显示随机数。更糟糕的是,它在我的水平进度条中根本没有显示任何值。
Log.d("MyLog", "The value of completed is " + completedtotal + " and total is " + total);
int temp = completedtotal / total;
temp = temp * 100;
String tempString = completedtotal + "/" + total + " Challenges Completed";
Button b = (Button) findViewById(R.id.button1);
b.setText(tempString);
ProgressBar pb = (ProgressBar) findViewById(R.id.prog);
Log.d("Mylog", "value is " + temp);
pb.setProgress(temp);
非常感谢!!
最佳答案
试试这个方法:
Button b = (Button) findViewById(R.id.button1);
b.setText(String.valueOf(completedtotal) + "/" + String.valueOf(total) + " Challenges Completed");
关于java - Android - 添加按钮标题时的随机整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909073/