1

I made a string array in xml and I would like to add values to each one. As they are currencies, each would have its own value but i'm unsure as to how to do it.

<string-array name="currencies">
    <item>EUR, Euro</item>
    <item>GBP, British Pound</item>
    <item>USD, US Dollar</item>
    </string-array>
4
  • How is this xml stored? Start there. Commented Jul 24, 2013 at 17:51
  • This is a valid string-array. What problem are you facing? Commented Jul 24, 2013 at 17:56
  • the xml is stored in res/values/strings.xml Commented Jul 24, 2013 at 18:00
  • @vikram the problem im facing is that i call the array in spinners in the java class. I want that when i select for example GBP that value 1.56 is selected also, as that is the value that is assigned to GBP Commented Jul 24, 2013 at 18:03

1 Answer 1

2

If you want to use this for preferences you should try this:

<string-array name="currencies">
    <item>EUR, Euro</item>
    <item>GBP, British Pound</item>
    <item>USD, US Dollar</item>
</string-array>

<string-array name="currenciesvalues">
    <item>1</item>
    <item>2</item>
    <item>3</item>
</string-array>

So the value of Euro is 1, the value of British Pound is 2, and so on. Like I said, if you use this in a preferenceactivity or preferencefragment, you can set the items, and the corresponding values like this:

android:entries="@array/currencies"
android:entryValues="@array/currenciesvalues"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.