Reputation: 13511
I keep getting warnings in Eclipse for hard-coding strings in my Android XML layout, but I think it makes more sense than putting everything in a string resource file and referencing it from there. I'm only going to use the said strings for that Activity anyway, and never again.
Are there any dangers into this kind of practice, like maybe initialization errors or performance issues, that I am overlooking? Why does Android encourage using a separate resource file?
Upvotes: 4
Views: 1229
Reputation: 56925
These files provide a central location for static application-wide data. Separating this data from the main application code could be seen as being beneficial to the overall application structure
There are a number of benefits to including string content as a resource, such as:
Upvotes: 1
Reputation: 8806
Keeping strings separate from your code and in resource files has a lot of advantages and is generally considered to be good practice.
First, it will keep all your strings in one place, so there is a quick way for you to maintain them in one file.
The most important reason is that of Internationalization. If you application has a need to support multiple languages
, then separating out your strings (test, button labels,etc) in different resource files for different languages helps to manage this process much better.
For more information, refer to http://developer.android.com/guide/topics/resources/localization.html
Upvotes: 0
Reputation: 60681
The main reason is for internationalization. Putting strings in resource files makes it much easier to provide separate translations of each string for different languages, without having to copy your layout files.
Upvotes: 4