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

share|improve this question

3  
might this be helpful stackoverflow.com/a/3044081/603744 – Andro Selva Jul 27 at 10:09
feedback

1 Answer

up vote 2 down vote accepted

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);
        }
share|improve this answer
1  
thanks imran khan – Romio Jul 27 at 10:22
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.