[android-beginners] Re: resource id references in XML files?
Works great, and good writeup. Thanks! On Nov 29, 6:44 pm, XCaffeinated ssatn...@gmail.com wrote: Hi Nurg, This is probably too late to help you, but maybe others would like to know. I've just posted a solution at anddev.org:http://www.anddev.org/xml_integer_array_resource_references_getintarr... Best of luck! XCaf -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: resource id references in XML files?
Hi Nurg, This is probably too late to help you, but maybe others would like to know. I've just posted a solution at anddev.org: http://www.anddev.org/xml_integer_array_resource_references_getintarray-t9268.html Best of luck! XCaf On Nov 13, 8:36 pm, Nurg stephen.lafl...@gmail.com wrote: Bump. On Nov 4, 7:12 pm, Nurg stephen.lafl...@gmail.com wrote: I'm attempting to set up arrays of resource ids in XML and choosing from them during runtime, but it appears the references are not resolving as I would expect. Here is an example of what I am doing in the arrays.xml file in my res/values directory: resources string-array name=pets itemcat/item itemdog/item /string-array integer-array name=cat item@drawable/cat/item item@raw/cat_meow1/item item@raw/cat_meow2/item /integer-array integer-array name=dog item@drawable/dog/item item@raw/dog_bark1/item item@raw/dog_bark2/item /integer-array /resources And in my code: private void setPet(String petType) { int arrayId = mResources.getIdentifier(petType, array, getPackageName()); int[] petResids = mResources.getIntArray(arrayId); BACKGROUND = petResids[0]; SOUND_PET1 = petResids[1]; SOUND_PET2 = petResids[2]; } What I am seeing: - The arrayId value is getting set to the correct resource id. - If I hardcode the resource ids (from R.java) in array.xml, everything works. - However, using the @ notation does not work -- the petResids array is filled with zeroes. I know that one can reference strings from the strings.xml file, colors from the colors.xml file, etc. Is it the case that the @ references are evaluated for only some XML files (like those in the layout or menu directories)? Or am I missing something more fundamental?- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: resource id references in XML files?
Bump. On Nov 4, 7:12 pm, Nurg stephen.lafl...@gmail.com wrote: I'm attempting to set up arrays of resource ids in XML and choosing from them during runtime, but it appears the references are not resolving as I would expect. Here is an example of what I am doing in the arrays.xml file in my res/values directory: resources string-array name=pets itemcat/item itemdog/item /string-array integer-array name=cat item@drawable/cat/item item@raw/cat_meow1/item item@raw/cat_meow2/item /integer-array integer-array name=dog item@drawable/dog/item item@raw/dog_bark1/item item@raw/dog_bark2/item /integer-array /resources And in my code: private void setPet(String petType) { int arrayId = mResources.getIdentifier(petType, array, getPackageName()); int[] petResids = mResources.getIntArray(arrayId); BACKGROUND = petResids[0]; SOUND_PET1 = petResids[1]; SOUND_PET2 = petResids[2]; } What I am seeing: - The arrayId value is getting set to the correct resource id. - If I hardcode the resource ids (from R.java) in array.xml, everything works. - However, using the @ notation does not work -- the petResids array is filled with zeroes. I know that one can reference strings from the strings.xml file, colors from the colors.xml file, etc. Is it the case that the @ references are evaluated for only some XML files (like those in the layout or menu directories)? Or am I missing something more fundamental? -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en