Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource arrays [duplicate]

Tags:

Is there a way to define an array in XML in which the elements are resource references? For example (it doesn't work, but it explains what I want):

<integer-array name="actions_images">     <item>@drawable/pencil</item>     <item>@drawable/pencil</item>     <item>@drawable/pencil</item>     <item>@drawable/pencil</item>     <item>@drawable/pencil</item>     <item>@drawable/pencil</item> </integer-array> 
like image 969
user940016 Avatar asked May 27 '12 14:05

user940016


People also ask

How do you prevent duplicate arrays?

To prevent adding duplicates to an array:Use the indexOf() method to check that the value is not present in the array. The indexOf method returns -1 if the value is not contained in the array. If the condition is met, push the value to the array.

How do you find duplicates in arrays?

Duplicate elements can be found using two loops. The outer loop will iterate through the array from 0 to length of the array. The outer loop will select an element. The inner loop will be used to compare the selected element with the rest of the elements of the array.

Can arrays have duplicates?

The standard way to find duplicate elements from an array is by using the HashSet data structure. If you remember, Set abstract data type doesn't allow duplicates. You can take advantage of this property to filter duplicate elements.

How do you remove duplicates from an array of arrays?

To remove duplicates from an array: First, convert an array of duplicates to a Set . The new Set will implicitly remove duplicate elements. Then, convert the set back to an array.


1 Answers

If I understand your question correctly, I think I know a workaround (since accessing them via getResources().getIntArray() doesn't work). (You can read more here, that is the source I took the workaround from.)

TypedArray ar = context.getResources().obtainTypedArray(R.array.my_array); int len = ar.length();      int[] resIds = new int[len];      for (int i = 0; i < len; i++)          resIds[i] = ar.getResourceId(i, 0);  ar.recycle();                        // Do stuff with resolved reference array, resIds[]...      for (int i = 0; i < len; i++)          Log.v (TAG, "Res Id " + i + " is " + Integer.toHexString(resIds[i])); 
like image 80
Thomas Calc Avatar answered Nov 15 '22 20:11

Thomas Calc