Working with Resources
You may have worked with resources a few times in this book, and at this point you’re likely familiar with using the
R class to access resources from within your application. If you’re rusty on resources and the generated
R file, see Chapter 3.
Moving strings into resources
As you become an experienced programmer, you may start to take shortcuts to get your project built and working. Say that initially you forget to move strings into resources, and you have to come back at a later time to do it. You can extract a string into a resource using the built-in tools.
The long way
Here’s one way to extract a string into a resource:
1. Create a new string resource.
2. Copy its name.
3. Replace the string value in your layout with the resource identifier.
This task may not be a huge pain, but it takes time, possibly 30 to 45 seconds for the average developer.
The fast way
You can cut the time to create a string resource to fewer than 15 seconds. If you do this 30 times a day (which is feasible in an 8-hour day), you can save 15 minutes of just copying and pasting. That’s five hours a month doing the copy-and-paste dance!
Follow these steps:
1. In Eclipse, open the
file in the
2. Find the following chunk of code in the file:
android:text=”Toggle Silent Mode”
3. Select ...