0

This is the part of my function that assigns an image to my ImageView. I can not get it to show an image. I have my files listed under assets/signs/"image names." This code came straight from my textbook with some minor tweaks to fit my code. I appreciate the help.

String nextImage = signNames.remove(0);
AssetManager assets = getAssets();
InputStream stream;
    try{
         stream = assets.open("signs/"+nextImage + ".gif");
         Drawable sign = Drawable.createFromStream(stream,nextImage +".gif" );
         signImageView.setImageDrawable(sign);
    }
    catch(IOException e){
         Log.e(TAG, "Error loading " +nextImage, e);
    }
Jonik
  • 80,077
  • 70
  • 264
  • 372
  • 1
    your signImageView is indeed an ImageView? – Eric H. Mar 08 '14 at 17:21
  • you have to use the help of movie class to play gif in image view here this link http://weavora.com/blog/2012/02/07/android-and-how-to-use-animated-gifs/ – Santhosh Mar 08 '14 at 17:25
  • Yes it is an ImageView. I've tried changing them to jpeg's, still nothing. I tried: int id = getResources().getIdentifier("yourpackagename:drawable/" + nextImage, null, null); signImageView.setImageResource(id); and nothing – user3396534 Mar 08 '14 at 18:48

1 Answers1

1

I think there is a much simpler idiom for what you are trying to do. No need to stream the image the want to display. Simply put the image in res/drawable (or res/drawable-hdpi, etc). Then simply:

 signImageView.setImageResource(R.drawable.myImage)

Of if you need to get the resource from a dynamic string:

int id = getResources().getIdentifier("yourpackagename:drawable/" + nextImage, null, null);
signImageView.setImageResource(R.drawable.myImage)

see here

This assumes your signImageView is indeed an ImageView.

Community
  • 1
  • 1
Eric H.
  • 6,894
  • 8
  • 43
  • 62