zomlaaa95 zomlaaa95 - 1 year ago 199
Android Question

Get resource id from typedarray

I have this file array.xml and I want to get the item value from an array.
How can I do that? I have tried with getInt but that returns 0. All help is welcome.

<array name="firstAd">

Answer Source

First, change each item to @id/object instead of R.id.object, then change the tag from array to integer-array, and move the code to your 'integer.xml' resource file.


<integer-array name="firstAd">

Then, programmatically use a TypedArray, like so:

TypedArray firstAd = getResources().obtainTypedArray(R.array.firstAd);
int resourceId = firstAd.getResourceId(index, defValue);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download