java - Android - 添加按钮标题时的随机整数值

标签 java android button android-progressbar

我正在使用一堆 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/

相关文章:

Javascript,有不同的按钮调用不同的功能

java - 多次调用 CompletableFuture#join 合适吗?

java - 由于存在粘性按钮而无法单击按钮

java - 如何在屏幕底部的选项卡布局中打开新 Activity android

android - 图库 - 通过触摸滚动不起作用

android - Firebase UserProfileChangeRequest 不工作

java - 使用Flink窗口和折叠功能,元素丢失?

java - 在处理后,在 Flink 中将元素传回输入流?

javascript - 我想制作一个点击后自动旋转的按钮

javascript - 选中所有复选框并启用按钮