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. Problems on Mac Android - Eclipse

I installed Eclipse v3.4.2 and latest version of Android SDK 1.5_r1.

My Eclipse works but when trying to change the Preferences -> Android
I get the following error messages:

Problem Occurred
'Android SDK Content Loader' has encountered a problem.
An internal error occurred during: "Android SDK Content Loader".

Android SDK Location
Failed to get the required ADT version number from the SDK.
The Android Developer Toolkit may not work properly.

Anyone any idea the reason of this?



2. ConnectivityManager isConnected REAL Network Connection FAIL

Hi I'm facing a problem with ConnectivityManager.

I check with ConnectivityManager if I'm connected


Returns true, but I can't route to host.

After this check I try to load a URL and shows me a "Web page not


How can I check if I have real access to network.   Maybe
requestRouteToHost but it have to be simpler.

Any solution to check REAL Network connection.


3. Is it possible to extend default applications?

4. Repeat Events in Calendar

5. get Pictures Folder Path.

6. How to make my Android Phone work as a Client to receive a file from a remote server

7. Communication protocols