4

I have a problem, a technical one. I have a list view, when I click an item I get content at that specific position and send it to next activity through 'putExtra'

On next activity what i am doing is

        String item;
        Bundle extras = getIntent().getExtras(); 
        if (extras != null) {
            item = extras.getString("item");
        }

Now lets say here item = "Java";

Now what I want is termsArray = getResources().getStringArray(R.array.Java);

But i donot want R.array.Java, I want some thing like R.array.item

String Arrays in XML

<string-array name="Java">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>

<string-array name="C">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>

<string-array name="php">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>

I can do this task using IF-else but I have many String Arrays, so it is not possible to use IF-else

1

1 Answer 1

16

try as:

 String item;
        Bundle extras = getIntent().getExtras(); 
        if (extras != null) {
            item = extras.getString("item");
            int arryid = this.getResources().getIdentifier(item, "array",
                this.getPackageName()); 
            termsArray  = this.getResources().getStringArray(arryid);
        }
0

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.