how to load the related Bitmap according to input

by wine » Wed, 07 Oct 2009 02:42:55 GMT

Sponsored Links

I have met an issue.
There are some pics in the res/drawable named as pic_1.png, pic_2.png,
pic_3.png, pic_4.png.... I want to load someone according to the
For instance, if I input 2, I want to load pic_2.png. If input 3, will
load the pic_3.png....
How to achieve? Need your expert help here...


how to load the related Bitmap according to input

by I82Much » Wed, 07 Oct 2009 19:12:42 GMT

 I take it you're looking for something a little more scalable than the
naive solution:

switch (input) {
    case 1:
        return R.drawable.pic_1;
    . . .
    case n:
        return R.drawable.pic_n;

I see the problem; you need to append an arbitrary number to the end
of a string, and then turn that into the R.drawable. ___ reference.
I'm stumped


Sponsored Links

how to load the related Bitmap according to input

by I82Much » Wed, 07 Oct 2009 19:15:33 GMT

 I suppose you could also do something like

int[] iconRefs = {

if (input >= 0 && input < n) {
    // Account for 0 based indexing
    return iconRefs[input - 1];

This code gets the reference out (I might be wrong in how you
reference it, maybe R.res.drawable, don't have my eclipse handy);
you'd have to use the standard way of actually getting that drawable


Other Threads

1. Good Luck to everyone !

Dear fellow developers

These have been some hard debugging months  (3 for me).

I have send my submission, and received the confirmation, so
everything is well, now I can get back to my family, and rest at night
once again :)

Would like to thank all the Google guys who took all our critics, and
still were here to help, and give some feedback on features and bugs,
much apreciated.

Would like to thank the community, which was a big help, in these
murky waters, of unexpected bugs and features :)

Which you all good luck on the contest.

And for the Google Guys, keep on Coding ... :D
You guys have to finish that think, and iron out all the bugs.

Logging off, going to crash now  ...........

See ya


2. Problem in using FileReader to read .txt files

Hello ,

I would like to know to read your file on your computer without adb
and push.

best regards,


3. BitmapDrawable is faster than Bitmap ?

4. ongoing battle with activity life cycle

5. talking to an external database

6. And drawPath is faster and many invocations of drawLine (between points) in Overlay ?

7. after creating an alarm service that starts on boot the adb tries to connect even after i stop the emulator, why is that?