I am building an Android app, and I have a problem to get resource from string.xml.
I need to have a URL in String.xml that will be used several times through the app.
I tried Resources.getText("my_url"), but this does not work. Eclipse complains when I use this.
Do you think this is the best way to do ?
What you probably want is:
The
getString()method is inContextwhich means that it’s available directly in yourActivityclass sinceActivityis a subclass ofContext. (ThegetString()method is also inResourcesbut it’s easier to call on it directly on yourActivity.)What happens with your XML resources is that each is given a unique integer ID and this is added to the automatically generated
Rclass as apublic static final int. You then use these IDs to reference the resources. Have a look in thegenfolder in your Eclipse project and you’ll find theRclass in there.