In my Java class I want to use a string resource from strings.xml.
For that I want to use something like this:
getString(R.string.address)
If my class is an activity then it’s working.
But how can I use it if my class is a simple Java class?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A class does not have a context and to use a string resource a context is needed. So just call the class from an activity and give a parameter
contextand within your class constructor just use that context to get the string resource.In your custom class you need to import the R namespace for the project to get the resource Id.
Then to get the actual string