Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R.string.value Help android notification

Tags:

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?

like image 582
Simon Avatar asked Jul 29 '10 13:07

Simon


2 Answers

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.

like image 150
Sephy Avatar answered Nov 28 '22 08:11

Sephy


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:

String s = mContext.getString(R.string.somestring) 
like image 37
sizreaper Avatar answered Nov 28 '22 07:11

sizreaper