6

I've been trying to implement simple (I think) thing in my app. I thought it would be simple, but somehow it doesn't work as I would wanted it to.

What I'm trying to do is:

  • There is an activity with ImageView in center - it has it's own image (well, there's two of them).
  • I want to press that ImageView (or it could be ImageButton), open the gallery/take picture with camera.
  • Then, after taking/picking a picture, I want to make that ImageView display the thumbnail of picture.

My layout

                <ImageView
                    android:id="@+id/add_photo_left"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="20dp"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@drawable/add_photo_button" />

                <ImageView
                    android:id="@+id/add_photo_right"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@drawable/add_photo_button" />
            </LinearLayout>

My code - after getting picture path

        BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
        bmpFactoryOptions.inSampleSize = 8;
        Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/5.png",bmpFactoryOptions);
        lastClicked.setImageBitmap(bitmap);
        //lastClicked.setImageResource(R.drawable.green_circle);

What I wanted to do is to read the resized file (using inSampleSize) from sdcard, and then fill ImageView (or ImageButton) with it. But after using setImageBitmap function, the view disappears - like it just loaded empty image (commented line works properly - it's just green dot).

Maybe someone has approached similar problem? I would much appreciate any kind of help.

Greetz, scana

EDIT: ofc lastClicked:

lastClicked = (ImageView)findViewById(R.id.add_photo_left);
scana
  • 2,785
  • 2
  • 25
  • 49

1 Answers1

5

Why don't you try lastClicked.invalidate() ?

I do so in my code at least and it works this way ;)

mjaskowski
  • 1,479
  • 1
  • 12
  • 16
  • 2
    Wow! That's my first accepted answer on stackoverflow.com :D It would be interesting to understand when one needs to invalidate() but I didn't find a good answer for that yesterday. – mjaskowski May 16 '12 at 12:45