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.

1
  • 1
    get rid of the id in the xml Commented Apr 24, 2014 at 9:23

2 Answers 2

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

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>

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.