Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

Sunday, November 4, 2012

Hardcoded string should use @string resource

Android Development Solution - use @String Resource

Android development Solution
Problem : I'm a beginner android developer , I was trying to run this Linear Layout in eclipse :
Code :
And, I noticed :
1) yellow line under android:text="Yellow"
2) yellow line under android:text="row four"
the Triangle warn says [I18N] Hardcoded string "Yellow", should use @string resource " and same for the rest of the warnings.Any suggestion?


Solution :

It is not good practice to hard code strings into your layout files. You should add them to a string resource file and then reference them from your layout.

This allows you to update every occurrence of the word "Yellow" in all layouts at the same time by just editing your strings.xml file.

It is also extremely useful for supporting multiple languages as a separate strings.xml file can be used for each supported language.



More Android articles :