1

i had many string-array's in xml of form

<resources>
    <string-array name="abc1">
        <item>text_string</item>
        <item>text_string</item>
        <item>text_string</item>
    </string-array>
    <string-array name="abc2">
        <item>text_string</item>
        <item>text_string</item>
        <item>text_string</item>
    </string-array>
    <string-array name="abc3">
        <item>text_string</item>
        <item>text_string</item>
        <item>text_string</item>
    </string-array>
    <string-array name="abc4">
        <item>text_string</item>
        <item>text_string</item>
        <item>text_string</item>
    </string-array>
</resources>

in my activity this is how i access them now

if(position==1){
static String[] hai = getResources().getStringArray(R.array.abc1);
}else if(position==2){
static String[] hai = getResources().getStringArray(R.array.abc2);
}else if(position==3){
static String[] hai = getResources().getStringArray(R.array.abc3);
}else if(position==4){
static String[] hai = getResources().getStringArray(R.array.abc4);
} 

But to reduce the code i need to do something like

string xyz="R.array.abc"+position;

so now my xyz contains R.array.abc1 or R.array.abc2 based on position, is their anyway that i could use the xyz to pass this in getStringArray function to get me what my working/above code achieved.

Maybe something like.

string xyz="R.array.abc"+position;
static String[] hai = getResources().getStringArray(xyz.tozzzz());
Ashok Varma
  • 3,489
  • 3
  • 28
  • 43
  • 1
    `a string of type “R.array.abc”` ... No, it's an **array of Strings**. – Phantômaxx Jan 02 '15 at 15:47
  • @DerGolem I had string xyz="R.array.abc" as you can see this is a string from. now i need to get string array by the command. String[] hai = getResources().getStringArray(R.array.abc); But what i had is xyz="R.array.abc", i can't pass String[] hai = getResources().getStringArray(xyz); because it is a string. Why you mentioned my question as duplicate - link the answer if it is? – Ashok Varma Jan 02 '15 at 16:04
  • Look, here's how to use string arrays: http://developer.android.com/guide/topics/resources/string-resource.html#StringArray – Phantômaxx Jan 02 '15 at 16:08
  • @DerGolem - i know the way to use string array, i ran in to a situtaion where i need to convert a string and i need to pass it in to that method and no documentation said about that. Please understand the question.Wait i will change the my question. – Ashok Varma Jan 02 '15 at 16:12
  • So, what is the question really about? passing an array (not needed, since you can reget it from the resources)? concatenating all the elements using a separator then splitting it again (I wonder why would you do such a thing)? – Phantômaxx Jan 02 '15 at 16:15
  • @DerGolem No i am editing the question, please wait a sec – Ashok Varma Jan 02 '15 at 16:19
  • @DerGolem please check my question now, as you can see my question is completely different remove duplication on it – Ashok Varma Jan 02 '15 at 16:26
  • Now it's clear. Simply use the answers in the given link to the similar post, and use "array" for the resource type. – Phantômaxx Jan 02 '15 at 16:29
  • @DerGolem Thanks bro got it. sorry i troubled u so much, i was just seeing the first comment all the time. The second comment had the answer.even first comment update had the answer. i didn't observed it. I taught you are not getting my question and made lot of mess here sorry for that – Ashok Varma Jan 02 '15 at 16:32

0 Answers0