如何将int转换为String? [英] How to Convert an int to a String?

查看:143
本文介绍了如何将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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆