我有一个 int 变量,当我将此变量设置为 Android TextView 的文本时,它会引发错误,可能是因为它是一个 Int。我已经检查但找不到 int 的 toString 函数。那我该怎么做呢?
int sdRate=5;
//text_Rate is a TextView
text_Rate.setText(sdRate); //gives error
最佳答案
使用 String.valueOf() :
int sdRate=5;
//text_Rate is a TextView
text_Rate.setText(String.valueOf(sdRate)); //no more errors
关于java - 如何将 int 转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4841559/