1

So I have a file like so

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="item_types">
        <item>Dry Food</item>
        <item>Produce</item>
        <item>Frozen Good</item>
        <item>Household Item</item>
    </string-array>
</resources>

And I am making a Dialog with some selection on it. I want to reuse these values in my layout. I would like to use them through my resources R. I would like to set this value I select from R to the android:text of an element.

Something like this in my mind...

...
<TextView
    ...
    android:text="@R.arrays.item_types.0" />
...

Obviously this does not work. I plan on making this Dialog programmatically in the future, but was wondering if I could set this text in the XML. I also plan on that array being changed by the user. So it would be nice if I did not have to statically define the text in the TextView.

I have a good idea of how I will do it in java. Just wondering if this could be done in one go via xml.

Thanks in advance.

Noah Herron
  • 630
  • 4
  • 23

1 Answers1

0

String[] list = getResources().getStringArray(R.array.item_types);

set the text of TextView programmatically (using TextView.setText) by accessing list[0] in java

Geetha
  • 190
  • 9