1

My ultimate goal is this: I have two spinners, spinner1, spinner2, each with their own values. One image, named image. There are strings, named start, end, file. One button, button.

My code looks as such:

@Override
public void onClick(View v) {
    start = sStart.getSelectedItem().toString();
    end = sEnd.getSelectedItem().toString();
    if (start.equals(end)) {
        Toast.makeText(this, "You cannot end where you start.",
                Toast.LENGTH_SHORT).show();
        works = false;
    }
    if (works) {
        start = start.replace(" ","_");
        end = end.replace(" ","_");
        file = "@drawable/" + start + end + ".gif";
    }
}

The file name matches the contents of start + end + ".gif" perfectly, so I would like to set the image to the file name which corresponds to the string's content.

Adam
  • 2,532
  • 1
  • 24
  • 34
  • 1
    see http://stackoverflow.com/questions/3042961/how-can-i-get-the-resource-id-of-an-image-if-i-know-its-name – njzk2 Sep 28 '12 at 15:03

1 Answers1

2

what i've done (more or less, i don't have my code in front of me), i put my image file in assets, then i create my method around :

InputStream stream = context.getAssets().open(filename);
Bitmap bmp = BitmapFactory.decodeStream(new BufferedInputStream(stream)); 

this reads file from assets and convert this to Bitmap

you coulkd also use context.getResources() but i don't remember what to do next

user902383
  • 8,420
  • 8
  • 43
  • 63