0

Ok so below is a snippet of my xml code:

<string-array name="country_data">
<item>
        <font color="#7c7b7b">
        <country>Afghanistan</country>
        <countryCode>93</countryCode>
        <iso2>AF</iso2>
        <iso3>AFG</iso3>
        </font>
    </item>

I want to display just the country in a spinner object. I can display all the data and can do it if I only have Country in the item but I want the rest of the data there too to reference elsewhere when needed.

My android Java code is as follows:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.country_data, android.R.layout.simple_spinner_item);

country_data is the name of the string-array. What should I change/add to just display Afghanistan instead of Afghanistan 93 AF AFG

Cronus
  • 1
  • 2
  • 1
    i think you'd have to make a custom adapter – a_local_nobody Sep 27 '19 at 13:37
  • You need an XML Parser. See [android-parsing-xml](https://stackoverflow.com/questions/3839372/android-parsing-xml) or [how-to-parse-xml-using-the-sax-parser](https://stackoverflow.com/questions/4827344/how-to-parse-xml-using-the-sax-parser) and many more...Android provides three types of XML parsers which are DOM,SAX and XMLPullParser.[android-XMLPullParser-tutorial](https://www.javatpoint.com/android-XMLPullParser-tutorial) – Jon Goodwin Sep 27 '19 at 13:50

1 Answers1

0

I think you need to modeling/create the mapping of the xml field

you can try this documenation https://developer.android.com/training/basics/network-ops/xml

indra lesmana
  • 246
  • 2
  • 7