我有一个int变量,当我将此变量设置为Android TextView的文本时,它会抛出一个错误,可能是因为它是一个Int.我已经检查但是找不到int的toString函数.那我该怎么办呢?
int sdRate=5;
//text_Rate is a TextView
text_Rate.setText(sdRate); //gives error
Run Code Online (Sandbox Code Playgroud)
Kon*_*rov 97
int sdRate=5;
//text_Rate is a TextView
text_Rate.setText(String.valueOf(sdRate)); //no more errors
Run Code Online (Sandbox Code Playgroud)
Sco*_* M. 13
使用Integer类的静态toString()方法.
int sdRate=5;
text_Rate.setText(Integer.toString(sdRate));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
115258 次 |
| 最近记录: |