views:

33

answers:

1

I have an XML resource file:

<resources>
    <section>
        <category value="1" resourceId="@xml/categoryData1" />
        <category value="2" resourceId="@xml/categoryData2" />
        <category value="3" resourceId="@xml/categoryData3" />
    </section>
</resources>

Using XmlPullParser, on the START_TAG, I can use:

int value = parser.getAttributeIntValue(null, "value", 0);

to get values 1, 2, 3...however:

int resourceId = parser.getAttributeIntValue(null, "resourceId", 0);

doesn't work...it just yields the default value 0, or whatever I change the default value (3rd parameter) to be...

Does anyone know what I am doing wrong or if this is possible?

+1  A: 

well, if you look in your resourceId attribute, it does not seem to contain an int, does it? Or am I misreading you?
you should instead use getAttributeValue and cast it in the right Type.

Sephy
I think you are misreading me, as I understand the resources in android, @xml/categoryData1 is the same as R.xml.categoryData1 which is an integer type.It's the same case when you use android:id="@id/element_id" in the xml elements...@id/element_id references an integer number.I'm completely new to java so please correct me if I am wrong.
Bruce Lee
as marcarse said, you should use an array, it is much easier
Sephy