Problem with strings.xml… can't pass R.string.foo as a CharSequence
-
29-09-2019 - |
Question
I'm running a TabActivity
. In the following line:
spec = tabHost.newTabSpec("alltime").setIndicator(R.string.plots_allTime)
.setContent(intent);
I get an error because setIndicator()
expects a CharSequence
. I'm not really sure how to fix this, because I should be able to pass a string into that parameter. I think the issue lies in the fact that the generated R.java
initializes everything in the strings.xml
file as public static final int
. The setIndicator() method doesn't seem to like that too much. Is there any way around this?
Solution
spec = tabHost.newTabSpec("alltime").setIndicator(getString(R.string.plots_allTime))
.setContent(intent);
OTHER TIPS
You need to get a string corresponding to the ID from R.string: use context.getText, which returns a localized, styled CharSequence from the application's package's default string table:
setIndicator(context.getText(R.string.plots_allTime) )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow