Android, resources, custom entities, and reuse, oh my!

Hello Android fans! Recently I ran into a situation where I wanted to reuse a certain string value as a sub-string in other resource values. I know you can use

to re-use a string across resource files, but you can not use the @string pointer as a substring, or concatenation. By the way the above might look odd, but its good practice in case the UI context for some_string_here ends up needing to be different then some_string_over_there at some point in the future, something that can very well occur in other languages.

Now, back to the question at hand, how can we re-use a string resource and be able to concatenate? Custom entities! Lets assume we want to re-use a string for the application name in a sentence. Then we can simply define the application name in a entity within the DOCTYPE declaration like so

Now to refer to this, just recall how we usually refer to a entity

This entry was posted in Android, Techy. Bookmark the permalink.