[英]TextView.setText(int resid)
Lets say I want a textview to display 5. 可以说我希望textview显示5。
I assume I can use TextView.setText(5). 我假设我可以使用TextView.setText(5)。
But in the above case, the compiler would be looking for a resource id 5 and not the integer 5. 但是在上述情况下,编译器将查找资源ID 5,而不是整数5。
What should I do if I really want to display the "integer" ?. 如果我真的想显示“整数”怎么办?
TextView.setText(Integer.toString(5))
转换为字符串
You need to cast it to String (now compiler won't it interpret as resource): 您需要将其强制转换为String(现在编译器不会将其解释为资源):
TextView.setText(5 + "").
TextView.setText(String.valueOf(5));
TextView.setText(Integer.toString(5));
TextView.setText(new Integer(5).toString());
Well, you actually have 5 (five) choices, but the first 2 are the most common. 好吧,您实际上有5个(五个)选择,但是前2个是最常见的。
1) txtTextView.setText(String.valueOf(5)) // or Integers's equivalent
1)
txtTextView.setText(String.valueOf(5)) // or Integers's equivalent
2) textTextView.setText(R.string.value_of_5) // this would be an int value declared in strings.xml
2)
textTextView.setText(R.string.value_of_5) // this would be an int value declared in strings.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.