Frank wrote: > I have 3 sound files in my raw folder and then this in /values/ > sounds.xml > <resources> > <array name="sounds"> > <item name="sound1" type="raw">R.raw.sound1</item> > <item name="sound2" type="raw">R.raw.sound2</item> > <item name="sound3c" type="raw">R.raw.sound3</item> > </array> > </resources>
??? First, R.raw only has meaning in Java. Second, I'm not aware you can have an array of type="raw". > I'm trying to load all the resource Id's into an int array so I can > pass it into the media player to say (mapping all sounds from a button > to a sound). > > I have tried everything I could find googleing this question: > TypedArray ar = context.getResources().obtainTypedArray(resourceId); > > int len = ar.length(); > int[] resIds = new int[len]; > for (int i = 0; i < len; i++) > resIds[i] = ar.getResourceId(i, 0); > ar.recycle(); > > Doesn't work, I get back an array of 0's. And of course > getResources().getIntArray(R.array.sounds); doesn't work either. I'm > going to keep trying (new to the API, so still reading/messing around) > but if anyone has a solution, or is the reflection method the only > workaround? At the end of the day, on the path you're going down, you're going to use reflection. Whether it is that you are directly using reflection, or you are passing strings to Resources#getIdentifier(), reflection is how that will get mapped to an ID. If you wish to use getIdentifier(), use a <string-array> resource, or your own XML (in res/xml/), or something. Also, cache the results of getIdentifier(). Better yet, just write yourself a code generator script that whips through res/raw/ for your sound files and builds up some Java structure (e.g., int[]) that gets injected into your source code. You get the benefits of not manually maintaining the list twice, and you avoid the reflection runtime costs. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in NYC: 1-2 May 2010: http://guruloft.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

