views:

313

answers:

3

I would like to create a list of Integers in the /res folder of an android project. However, I want those integers to point resources in /res/raw. So for example, I would like something like this:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <integer-array name="built_in_sounds">
            <item>@raw/sound</item>
    </integer-array>
</resources>

But id doesn't look like I can do that, is there any way to do this? Or should I just create the list in a java class?

Thank you

A: 

Hi Leif,

In this case, I think it's not a good idea to use two integers just to control a resource (sorry for my English skill, it may cause you misunderstand) I mean, each resource has its own integer id in the class R in the gen folder, and now you create another integer to display the id, it's no need to do that.

I have some trick to handle what you want: Rename the resources you want in order, and in R class, they will be in order and increase by 1, then you can use that.

Here is an example: I have 5 resources in raw folder, they are: sound01, sound02, sound03, sound04, sound05

And in the R file, I get:

public static final class raw {
        public static final int sound01=0x7f040000;
        public static final int sound02=0x7f040001;
        public static final int sound03=0x7f040002;
        public static final int sound04=0x7f040003;
        public static final int sound05=0x7f040004;
    }

It's an array of integers, right?

And for the for loop, example:

for(int i = R.raw.sound01; i<= R.raw.sound02; i++) {
//do somethings
}

Since my English skill is not good, hope you can get my point!

Bino
Hmm...okay, it looks like that could work...although it does seem like a bit of a hack, and it seems likely that the android sdk could easily change to deprecate that. It also seems like it would be better than, to just have an Array class, that consists of all of the pointers. (I can do that in java in about 20 seconds, it just seemed like it would go against the spirit of putting the resources in the /res, and not /src folder). Thank you anyway, and that is a really interesting piece of info.
Leif Andersen
A: 

Okay, I finally found out how to do this. What I did, was just create a database. The database stored all of the primitives I needed to store, and than pointers to the objects that I needed to reference. Apparently the android SDK comes with support for SQLite.

Leif Andersen
A: 

To do this in XML without a database, see: http://developer.android.com/guide/topics/resources/more-resources.html#Integer

-flappit.com

Dave