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

Romio
  • 140
  • 1
  • 8

1 Answers1

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);
        }
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213