0

I have an array in the Array.xml from resources folder with the next content.

<resources>

    <string-array name="songs">
        <item name="id">1</item><item name="title">song1</item>
        <item name="id">2</item><item name="title">song2</item>
        <item name="id">3</item><item name="title">song3</item>
        <item name="id">4</item><item name="title">song</item>
    </string-array>

</resources>

I'm getting the values of the array with the next:

songs_array = Arrays.asList(getResources().getStringArray(R.array.songs));

But it shows me:

1
song1
2
song2
3
song3
4
song4

I want to know if there is a way to get only the title to show:

song1
song2
song3
song4

Thank you.

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94

2 Answers2

1

Your array looks actually like this:

<string-array name="songs">
    <item name="id">1</item>
    <item name="title">song1</item>
    <item name="id">2</item>
    <item name="title">song2</item>
    <item name="id">3</item>
    <item name="title">song3</item>
    <item name="id">4</item>
    <item name="title">song</item>
</string-array>

That's why you get the result that way. As Raghunandan mentioned, get rid of the id ;)

Rusher0
  • 11
  • 2
0

I've understand the problem. There is no difference between the items. So, the ids need to be deleted, I will need to make the ids in another way.

Thank you.

<string-array name="songs">

    <item name="title">song1</item>
    <item name="title">song2</item>
    <item name="title">song3</item>
    <item name="title">song</item>

</string-array>
Víctor Martín
  • 3,352
  • 7
  • 48
  • 94