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?
You could use
String s = getResources().getString(R.string.value);
also.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 :If you open the R class you will see that it contains only numbers that are references to the compiled resources of your project.
R.string.value returns the reference ID number of the resource 'value'. If you look at your R class it will appear as something like this:
I've been experiencing issues with referencing the getString() method. The exact error that Eclipse spits at me is:
After reading for awhile I've figured out that you must reference your application's context to get access to the getString() method. I was trying to create a private SQLDatabase helper class in a content provider, however, that was not allowing me to reference the getString() method. My solution so far is to do something like this:
Notice these two context references:
I don't know if this is the optimal long-term solution but it seems to work for the moment. Hope this helps.
To retrieve the string, you need to use getString(),
but getString() is a method from Context class. If you want to use this method outside your Activity class, you should get link to your context first and then call: