Problem with strings.xml ... cannot pass R.string.foo as CharSequence

I am launching TabActivity . In the next line:

 spec = tabHost.newTabSpec("alltime").setIndicator(R.string.plots_allTime) .setContent(intent); 

I get an error because setIndicator() expecting CharSequence . I am not sure how to fix this because I have to pass a string to this parameter. I think the problem is that the generated R.java initializes everything in the strings.xml file as public static final int . The setIndicator () method seems to be too different. Is there any way around this?

+4
source share
2 answers
 spec = tabHost.newTabSpec("alltime").setIndicator(getString(R.string.plots_allTime)) .setContent(intent); 
+15
source

You need to get the row corresponding to the ID from R.string: use context.getText, which returns a localized, stylized CharSequence from the default row table of the application package:

 setIndicator(context.getText(R.string.plots_allTime) ) 
+10
source

All Articles