简体   繁体   中英

TextView.setText(int resid)

Lets say I want a textview to display 5.

I assume I can use TextView.setText(5).

But in the above case, the compiler would be looking for a resource id 5 and not the integer 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):

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.

setText

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM