We can read a string array from xml file in android like mentioned here. But this can only read simple string array.
My question is that can we read array containing some other type of objects. xml file is like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="difficulty_level_names">
<item>
<name>IELTS</name>
<type>1</type>
</item>
<item>
<name>SAT</name>
<type>2</type>
</item>
................
.........
</string-array>
</resources>
UPDATE: Of course, there can be more parameters in each item..
No, in the way you provided. I have two solutions on my mind, and both not ideal.
1.
You can create multiple arrays, for example string-array for names, integer-array for integer etc. Every object would be stored in those arrays at the same index. It’s not simple to maintain but it may be more memory efficient in case of accesing only one property from object.
I described it in: https://stackoverflow.com/a/6774856/538169
Or
2.
You can create one typed array and have object’s properties in the array. You could access the property through translating the index in such way:
Then get this property from TypedArray.
The second solution is much worse to maintain. Adding another property would be a nightmare.