Inquiring minds want to know: Why can't I just hardcode xml strings in android?
Why do I have to put strings into a resource file
XML file saved at res/values/strings.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
</resources>
and use weird syntax to retrieve them into a view?
<TextViewinstead of just hardcoding them?
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
The issue of using literal constants instead of named constants comes up as students first learn a high-level programming language. Why use a named constant (declared and assigned) instead of just using the actual constant value right in your code?
Do you recall the justification for this construct--unfortunately this is not presented in the intro text by Sedgewick and Wayne, but most student learn the benefit (and the typography convention in Java--ALL CAPS).
More on this later, ... .
Here is a hint for the deeper reason for an Android developer:
http://developer.android.com/guide/topics/resources/localization.html
http://developer.android.com/guide/topics/resources/string-resource.html