1

I have a string array say

<string-array name="temp">
    <item>
        Some Data1
    </item>
    <item>
        Some Data2
    </item>
    <item>
        Some Data3
    </item>
</string-array>

Suppose I want to get Some Data2 from this array, I know I can do

String temp[]=getResource().getStringArray(R.array.temp);

But instead of getting whole string array, I want only a specific item because data of whole string is too large, and I know its position. Please help.

2
  • 1
    you can not get a single item directly , you have get the whole array and then get the data use temp[1].... Commented Sep 19, 2015 at 13:07
  • Sir the thing is that I don't want to get whole array because data is too large, so I only want to get item but not array. Commented Sep 19, 2015 at 13:10

2 Answers 2

3

Assuming the entry you want is at position 2 (just an example), then do:

String myEntry = getResource().getStringArray(R.array.temp)[2];
Sign up to request clarification or add additional context in comments.

Comments

1

This is not possible.But If you want to do that just create string array in java class like

String arr[] = {"item1","item2","item3"}. 

And access those value using arr[1];

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.