I have a list of static key/value pairs that I need to include in my project like this one:
givenName : First Name
sn : Last Name
mail : Email
... snip ...
Where in an Android project would I put this?
Thanks Eric
You need a XML file saved at res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="givenName">First Name</string>
<string name="sn">Last Name</string>
<string name="mail">Email</string>
</resources>
Here is how you can access the values from other xmls:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/givenName" />
Or this is how you can access the value from Java code:
String string = getString(R.string.givenName);
Log.d("Test", string); // Outputs "First Name" to LogCat console.
Check this Android Dev Guide for full reference on String Resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With