[android-developers] Re: Select image resource dynamically
You can also use something like: int rid = getResources().getIdentifier("fr", "drawable", getPackageName ()); not the most efficient way but definitely something you can use. On Dec 19, 6:16 pm, croco wrote: > Hello Sergiu, > > I keep your hint in mind, > > for now i've generated the mapping class. Maybe not the best way but > it is sync with what i have in folder. > > Regards. > > Croco > On Dec 19, 2:42 pm, Sergiu Dogaru wrote: > > > > > you could try using Reflection, but that might be too complicated for > > what you need. > > What I would do is to place all of the images in the assets folder, > > where you can retrieve them by name. > > I think it's something like > > > Bitmap bmp = BitmapFactory.decodeStream(getResources().getAssets > > ().openFile("fr.png")); > > > On Dec 19, 3:17 pm, croco wrote: > > > > Hi all, > > > > I'm facing a problem, > > > > I've added a folder of 350 images representing country flags in my > > > project > > > > according the device country given by locale. Let's say fr for France > > > > I would like set an image with fr.png which is in the res/drawable > > > folder. How to achieve this without maintaining an ugly map in the > > > code saying fr = R.drawable.fr etc etc . > > > > Thank you for your help. > > > > Croco -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Select image resource dynamically
Hello Sergiu, I keep your hint in mind, for now i've generated the mapping class. Maybe not the best way but it is sync with what i have in folder. Regards. Croco On Dec 19, 2:42 pm, Sergiu Dogaru wrote: > you could try using Reflection, but that might be too complicated for > what you need. > What I would do is to place all of the images in the assets folder, > where you can retrieve them by name. > I think it's something like > > Bitmap bmp = BitmapFactory.decodeStream(getResources().getAssets > ().openFile("fr.png")); > > On Dec 19, 3:17 pm, croco wrote: > > > Hi all, > > > I'm facing a problem, > > > I've added a folder of 350 images representing country flags in my > > project > > > according the device country given by locale. Let's say fr for France > > > I would like set an image with fr.png which is in the res/drawable > > folder. How to achieve this without maintaining an ugly map in the > > code saying fr = R.drawable.fr etc etc . > > > Thank you for your help. > > > Croco > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Select image resource dynamically
Hello Sergiu, I keep your hint in mind, for now i've generated the mapping class. Maybe not the best way but it is sync with what i have in folder. Regards. Croco On Sat, Dec 19, 2009 at 2:42 PM, Sergiu Dogaru wrote: > you could try using Reflection, but that might be too complicated for > what you need. > What I would do is to place all of the images in the assets folder, > where you can retrieve them by name. > I think it's something like > > Bitmap bmp = BitmapFactory.decodeStream(getResources().getAssets > ().openFile("fr.png")); > > > > On Dec 19, 3:17 pm, croco wrote: > > Hi all, > > > > I'm facing a problem, > > > > I've added a folder of 350 images representing country flags in my > > project > > > > according the device country given by locale. Let's say fr for France > > > > I would like set an image with fr.png which is in the res/drawable > > folder. How to achieve this without maintaining an ugly map in the > > code saying fr = R.drawable.fr etc etc . > > > > Thank you for your help. > > > > Croco > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Select image resource dynamically
you could try using Reflection, but that might be too complicated for what you need. What I would do is to place all of the images in the assets folder, where you can retrieve them by name. I think it's something like Bitmap bmp = BitmapFactory.decodeStream(getResources().getAssets ().openFile("fr.png")); On Dec 19, 3:17 pm, croco wrote: > Hi all, > > I'm facing a problem, > > I've added a folder of 350 images representing country flags in my > project > > according the device country given by locale. Let's say fr for France > > I would like set an image with fr.png which is in the res/drawable > folder. How to achieve this without maintaining an ugly map in the > code saying fr = R.drawable.fr etc etc . > > Thank you for your help. > > Croco -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en