0

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" ?.

user2817836
  • 205
  • 2
  • 6
  • possible duplicate of [Integer value in TextView](http://stackoverflow.com/questions/3994315/integer-value-in-textview) – laalto Sep 26 '13 at 09:55

4 Answers4

5
TextView.setText(Integer.toString(5))

convert to string

Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
2

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));
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
1
TextView.setText(new Integer(5).toString());
Prabhakaran Ramaswamy
  • 25,706
  • 10
  • 57
  • 64
1

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

Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58