R.drawable.....

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

R.drawable.....

Postby egyptian » Thu Feb 04, 2010 6:46 am

Alright. This has had me stumped for quite a while and I'm beginning to think it's impossible.

I would like to create some sort of Array of drawables to decrease the amount of code I have... IE:

PSUEDO
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. images[] = {image1, image2, image3, image4, image5}
  2.  
  3.  
  4.  
  5. for(int i = 0; i < 5; i++)
  6.  
  7.  thedrawable = BitmapFactory.decodeResource(res,R.drawable.images[i]);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The above example is not real code or anything but shows that I would like to use some sort of array for the drawables rather than having to have the "BitmapFactory.decodeResource(res,R.drawable.imageX);" on each line where I select an image.......
Without God, I would not have ANY skills.
egyptian
Developer
Developer
 
Posts: 36
Joined: Fri Jan 16, 2009 5:45 am
Location: Lee's Summit, Missouri

Top

Postby pskink » Thu Feb 04, 2010 8:23 am

and your problem is...?

please elaborate
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby egyptian » Thu Feb 04, 2010 3:47 pm

The problem is that the above code doesn't work. R. drawable.... is an int. I'm not seeing a way to automate the name of the int.

Say I had 10 images: image1, image2, image3 ....

Is there a way to automate and use "image"+i (i being the number at the end)?
Without God, I would not have ANY skills.
egyptian
Developer
Developer
 
Posts: 36
Joined: Fri Jan 16, 2009 5:45 am
Location: Lee's Summit, Missouri

Postby pskink » Thu Feb 04, 2010 4:24 pm

egyptian wrote:Is there a way to automate and use "image"+i (i being the number at the end)?


int id = res.getIdentifier("drawable/image0", null, ctx.getPackageName())

assertTrue(id == R.drawable.image0)
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests