android关于TextView的setText()与Integer之间一个易犯的小错误

因为TextView有两个不同的重载函数,而且其中一个重载函数参数为int型的,但这个参数是Resource id,所以如果你想往setText中放入int或者Integer的引用(非资源引用)时,应先把它转成String。

例如:

Integer score = 123;

scoreTextView.setText(score); 这是错误的。

scoreTextView.setText(score.toString()); 这是正确的。

猜你喜欢

转载自blog.csdn.net/qq_36135335/article/details/82979569