Android strings.xml Best Practices? [closed] Android strings.xml Best Practices? [closed] android android

Android strings.xml Best Practices? [closed]


I'm still new at this, so I was looking for an example project. Astrid is open source on Github, and looking through the projects res directory was eye opening for a newbie like me.

Good stuff. Take a look:

https://github.com/todoroo/astrid/tree/master/astrid/res/values


Nice question. Im struggling with this too. My naming scheme is:

1) UI elements:If a string only corresponds to a ui i name it accordingly to the control element and the purpose, as well as in which part of the control element it is used. example:

button_helpText;control : button, purpose: help, context: Text;

2) General elements:If a string is used on the UI but i want to use it in another context i just leave the prefix and add a postfix to describe the purpose / context mor precise.

helpMessageHeading;purpose: help; context: a Message (abstract, could be a dialog), context_of_dialog: Heading; (the heading of a help dialog)helpMessageText;purpose: help, context: a Message (abstract, could be a dialog), context_of_dialog: Text; (the text inside a help dialog)helpExplanation;purpose: help; context_of_help: Explanation (just a explanation of the help topic)

3) Ordering:I order those string mainly based on their context as it is what you normally search for.

<!-- buttons -->...<!-- dialogs -->...<!-- general -->...<!-- explanations -->...

and so on. So my list is normally seperated in UI controls and, if a string is not bound to it, its general precise context. Why do i use the precise context ? when you search for a string to describe what you do the most unique idea about this string is its precise context, so thats what should pop up first. But when you use auto-completion you normally search for the general description. i think this structure is a fine solution.

I im very interested in other answers.


The best place to check out conventions would most likely be within the Android SDK samples. Here's how you can find them -http://developer.android.com/tools/samples/index.html