views:

264

answers:

1

whats the deal with

 CharSequence contentTitle = R.string.value;

Error cannot convert from int to CharSequence. Is there a way around this or am i missing something? i tried

String s = R.string.value + "";
CharSequence contentTitle = s;

it returns integers values. Any help?

+2  A: 

R.string.value is a call to the static field in the class R, which is auto generated by Eclipse and which does a kind of summary of all your resources. To retrieve the string, you need to use :

CharSequence contentTitle = getString(R.string.value);

If you open the R class you will see that it contains only numbers that are references to the compiled resources of your project.

Sephy
worked great. thanks
Simon
@Sephy I'm having an issue with getString(), I keep getting "The method getString(int) is undefined..." what am I doing wrong?
mlevit
What do try getting with this method?
Sephy
@Sephy I'm just trying to retrieve the actual value stored in strings.xml
mlevit
This is quite weird, I can't answer you just like that, I would need to see your code. Maybe you are doing something wrong. Do you know that this method is either associated to a context instance OR a Resource instance. So, maybe this is your issue.
Sephy
Perhaps this would help solve he problem? => context.getString(R.string.value)
conandor
Indeed, that's what I was suggesting. Thank you for the precision
Sephy