tags:

views:

24

answers:

1

I have about 25 pictures in my res/drawables. I want to loop through them, setting the next one as the background everytime the user hits a button on the screen.

Of course the drawables folder also has other pictures like droid icon etc which I don't want to use.

Cannot think of a good way of doing it. I thought of naming my pictures back1.jpg, back2.jpg... back25.jpg, and somehow looping through but this doesn't work. Can someone suggest a way/ sample code?

+1  A: 

I can think of three possibilities:

1)

Having a special folder in the assets res dir.

From the docs raw/:

However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

2)

Have this static images in the /res/drawable folder and a small HashMap with the images that can be used as background.

3)

  • Create an image.zip with all your backgrounds and place it on /res/raw
  • On the first run extract to /sdcard/yourapp/backgrounds/
  • Show only the images on that directory.

Depending on your app you can choose any of them.

Macarse
Thansk for taking the time to answer. I am away from the work right now so cannot try these, will try your suggestions soon.
OceanBlue
OceanBlue