Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add string resources in Eclipse?

Can I have Eclipse adding my string resources as I code or do I have to switch to string.xml all the time and add each string?

like image 533
Erik Z Avatar asked May 24 '11 05:05

Erik Z


People also ask

How do you add string resources?

android:text="@string/hello" />String string = getString (R. string. hello);

How do I add a new line to an XML string?

Add \t for tab and \n for new line.

Why do we store strings as resources in XML?

The purpose of strings. xml (and other *. xml resource files) is to regroup similar values in one place. This facilitates finding values that would be otherwise buried in the code.


1 Answers

Eclipse will sort of do it for you. So if you have a field:

android:text="hello"

Select "hello" and then goto Refactor-->Android-->Extract Android String, Eclipse will change the line to:

android:text="@string/hello"

and automagically add the line to strings.xml as:

<string name="hello">Hello</string>

JAL

like image 56
JAL Avatar answered Oct 24 '22 04:10

JAL