Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access a string-array item in Android?

snip-code from values/string.xml:

<array name="categories">
    <item name="today">Today</item>
    <item name="life">Life</item>
    <item name="corner">Corner</item>
    <item name="banks">Banks</item>
    <item name="it">IT</item>
    <item name="fun">Fun</item>
</array>

snip-code from layout/main.xml:

<Button
    android:id="@+id/today"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="8sp"
    android:text="@array/categories"
    />

Is it possible to assign a label-name to a Button with id=today directly from values/string.xml using string-array with name=categories and specific item, in this case - today?

like image 945
nenito Avatar asked Jul 04 '11 12:07

nenito


1 Answers

See the selected answer here: Android - reference a string in a string array resource with xml.

According to that answer, have to do something like this:

<string name="earth">Earth</string>
<string name="moon">Moon</string>

<string-array name="system">
    <item>@string/earth</item>
    <item>@string/moon</item>
</string-array>

Then you would simply do:

  <Button ....
  android:text="@string/earth" />
like image 191
Fraggle Avatar answered Oct 23 '22 16:10

Fraggle