0

I have an array of objects and want to represent them in an resource array. The class is defined like this:

class MyItem{
    private int id;
    private int price;
    private String name;
    private String desc;

    //getters and setters here
}

not sure about the syntax... but I tried this way:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="Category01">
        <item>
            <array>
                <item name="name">Name</item>
                <item name="desc">Description</item>
                <item name="imageId">0000000</item>
                <item name="price">100</item>
            </array>
        </item>
    </array>
</resources>

not working... how to represent my array of objects in resources ?? thanks

1 Answer 1

1

First of all, you need to clean up your XML: you've got two arrays representing the same thing. Try:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="Category01">
        <item name="name">Name</item>
        <item name="desc">Description</item>
        <item name="imageId">0000000</item>
        <item name="price">100</item>
    </array>
</resources>

Now, the question whether you can create a resource array of POJO's, It is THEORETICALLY possible. If it isn't, in your getters and setters, convert all int's to Strings using Integer.toString(int) and Integer.parseInt(String).

Sign up to request clarification or add additional context in comments.

2 Comments

That way wouldnt each item of the array be a field of my object ?
OK, do you want them to be fields or XML? If you want these "variables" defined in an XML resource, then they won't be fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.