Android setText()函数传入Int类型参数分析

setText()之类函数参数为string,如果传入Integer类型数据,会对资源进行搜索,并返回无该id资源错误,所以解决的方法只有一个就是设置setText(string

上述string参数就有两种方式来输入,

方法1:

setText(R.string.*),通过SourceID的方式定位到string,然后传入

方法2:把int类型强制转换成string类型

1)setText(int+"")

2)setText(String.valueOf(int))

猜你喜欢

转载自blog.csdn.net/kepengs/article/details/106443207