如何将int转换为String?

编程入门 行业动态 更新时间:2024-10-17 21:15:08
本文介绍了如何将int转换为String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个int变量,当我将此变量设置为Android TextView的文本时,它会抛出一个错误,可能是因为它是一个Int。我已经检查但是找不到int的toString函数。那我怎么能这样做呢?

I have an int variable and when I am setting this variable as an Android TextView's text it's throwing an error, maybe because it's an Int. I have checked but couldn't find a toString function for the int. So how can I do that?

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

更多推荐

如何将int转换为String?

本文发布于:2023-06-08 21:30:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589401.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   int   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!