0

I am trying to read a xml file with strings and int, and the array I get only have the strings, where there is supposed to be a int , it shows null... this is my xml file arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="questionnaire">
    <item>Quelle est la capital du Venezuela?</item>
    <item>4</item>
    <item>Maracay</item>
    <item>Caracas</item>
    <item>Valencia</item>
    <item>San Cristobal</item>
    <item>2</item>
</array>
</resources>

this is my java code

typeQuestion = getResources().getStringArray(R.array.questionnaire);

I thought my array typeQuestion would get the number 4 and 2 as strings, but it doesnt do it, that position is null in the array.....what can i do , to get the 4 and 2 as strings in the array??

2 Answers 2

1

If you want to use both string and int in String.xml file means use string-array instead of array .

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="questionnaire">
<item>Quelle est la capital du Venezuela?</item>
<item>4</item>
<item>Maracay</item>
<item>Caracas</item>
<item>Valencia</item>
<item>San Cristobal</item>
<item>2</item>
</resources>
</string-array>
Sign up to request clarification or add additional context in comments.

Comments

0
   <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string-array name="questionnaire">
    <item>Quelle est la capital du Venezuela?</item>
            <item>4</item>
            <item>Maracay</item>
            <item>Caracas</item>
            <item>Valencia</item>
            <item>San Cristobal</item>
            <item>2</item>
   </string-array>
   </resources>

Use string-array instead of using only array in the resources as then the integers entered by you will also be read as string and hence will be visible when you get the resource

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.