0

I am learning Android development at the moment by making a currency exchange app. I found a list of all the world currency codes in an XML file (https://www.currency-iso.org/dam/downloads/lists/list_one.xml). I want to use this XML file as a resource for my options in the spinner. Basically, I want something like this:

<resources>
    <string-array name="cur_array">
        <item>USD</item>
        <item>CAD</item>
        <item>GBP</item>
    </string-array>
</resources>

Of course, I need more than just these three currencies, I want ALL the currencies listed in that XML file above.

So how can I make this work? What approach is best?

harsh.gupta
  • 45
  • 2
  • 10
  • parse that xml using xml parsers which is available from that link and add them into a list and then pass that list to your spinner – Vivek Mishra Jul 14 '17 at 13:35
  • parse xml to custom object and then use spinner adapter with custom object – Pavya Jul 14 '17 at 13:53

2 Answers2

0

Answer taken from here: https://stackoverflow.com/a/4029623/1945115

In your strings.xml define:

<string-array name="array_name">
    <item>Array Item One</item>
    <item>Array Item Two</item>
    <item>Array Item Three</item>
</string-array>

In your layout:

<Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/array_name"
    />
Alexandr
  • 708
  • 9
  • 29
  • this is not my question. I know how to set up a spinner. please re-read the question – harsh.gupta Jul 14 '17 at 13:46
  • I understand now. But do you really need it in an XML format? Wouldn't something like http://android-er.blogspot.ro/2014/05/display-available-currencies.html this help? – Alexandr Jul 14 '17 at 13:50
0

Create a model according to xls of this page. Then convert xml to list of object. https://developer.android.com/training/basics/network-ops/xml.html

After you parser result to list of model, you can render this values with a adapter.

Sinan Kozak
  • 3,236
  • 2
  • 26
  • 32