I can set text by simply doing setText(R.string.value)
, for example. I receive no compile or runtime errors. I learned this by mistake, as I always use to set text by getting my string values from resources, such as setText(getResources().getString(R.string.value)
. What is the difference? Has Android evolved to where it no longer requires the getResources() method? Will older devices be compatible?
Asked
Active
Viewed 118 times
2

portfoliobuilder
- 7,556
- 14
- 76
- 136
1 Answers
3
This has actually been possible forever if you look at the TextView
documentation: https://developer.android.com/reference/android/widget/TextView.html#setText(int)
There are also some other setText(…)
methods in there which you might check out.
I'm generally never using the resource id's directly to display the text because it's like your said not generally known and causes some distraction for people not used to it. But I don't think that there are any benefits/drawbacks from using either of these two.

finki
- 2,063
- 1
- 20
- 23
-
1Interesting, thanks! I guess I never really noticed. – portfoliobuilder Nov 09 '17 at 18:49