RGS
RGS

Reputation: 4253

send image onclick to zoom activity

I'm trying to send an image to zoom activity from my main_activity.

I have a onclick function:

   case R.id.imageViewHero:

            String image = ViewHolder.this.post.getImageUrl();

            Intent intentv = new Intent(context, Zoom.class);

            Bundle extras = new Bundle();
            extras.putParcelable("imagebitmap", image);
            intentv.putExtras(extras);
            context.startActivity(intentv);

break;

the problem is the string image, I don't know what to do next to send it to zoom. Any ideas?

my zoom.class if needed:

public class Zoom  extends Activity {


@SuppressLint("NewApi")



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_zoom);

    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");

    ImageView imgDisplay;
    Button btnClose;


    imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
    btnClose = (Button) findViewById(R.id.btnClose);


    btnClose.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Zoom.this.finish();
        }
    });


    imgDisplay.setImageBitmap(bmp );

}

}

Upvotes: 0

Views: 537

Answers (2)

Asutosh Panda
Asutosh Panda

Reputation: 1473

The code is correct for most part except one mistake in making the Bitmap from the image URL.

You cannot make a Bitmap image from an image URL like you have done.

Its already been answered on StackOverflow. Check this link on how to convert an Image from an Image URL to a Bitmap - How to get bitmap from a url in android?

Basically, you are getting an Image URL from Intent which you are passing from the previous Activity, in the Zoom Activity, save it to a String variable, make Bitmap from it, set the Bitmap to the ImageView.

Upvotes: 1

Sangharsh
Sangharsh

Reputation: 3019

In onClick method, you seem to send imageUrl. However in Zoom.java you're treating it as Bitmap.

You can use a library like Picasso to populate ImageView using Image URL

Upvotes: 1

Related Questions