...">

How do I get an array counter from a resource file?

I have multiple arrays in resources like this:

<resources>
<string-array name="myArray1"> 
    <item>String1</item> 
    <item>String2</item> 
    <item>String3</item> 
</string-array> 

<string-array name="myArray2"> 
    <item>String1</item> 
    <item>String2</item> 
    <item>String3</item> 
</string-array> 

<string-array name="myArray3"> 
    <item>String1</item> 
    <item>String2</item> 
    <item>String3</item> 
</string-array> 
</resources>

      

Now, how to get the number of these arrays dynamically? I currently have 3 arrays.

I can get specific elements of an array like this

String[] resourceString =getResources().getStringArray(R.array.myArray);

      

But how do you get an invoice?

+3


source to share


3 answers


int length =getResources().getStringArray(R.array.myArray).length;

      



+6


source


XML file is not meant to count arrays within it. It is designed to store information that does not belong to your code in a static way.

This way you can change the menu, list it dynamically .



What you can do is not create multiple arrays, but store it ** multidimensional **. link

You can now count the arrays as user1969053 suggests

0


source


I see no point in dynamically getting the number of arrays from resources.

Since resource files cannot be changed dynamically, the counter will never change.

and since you have developed the application, you know how many arrays you have stored in the application resource.

0


source







All Articles