Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get ImageView's image and send it to an activity with Intent

I have a grid of many products in my app. when the user selects one of the item in the grid, I am starting a new activity as DIALOG box and display the item's name,quantity and image. But I cannot send the image source dynamically.

here is my code

gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
            //Toast.makeText(getApplicationContext(),((TextView) v.findViewById(R.id.grid_item_label)).getText(), Toast.LENGTH_SHORT).show();
            Intent item_intent = new Intent(MainActivity.this, Item.class);
            item_intent.putExtra("name",((TextView) v.findViewById(R.id.grid_item_label)).getText());
            item_intent.putExtra("quantity",((TextView) v.findViewById(R.id.grid_item_quantity)).getText());

            //my problem is here***************************************************
            ImageView my_image =  findViewById(R.id.grid_item_image).getDrawable();
            item_intent.putExtra("image",my_image.getXXXXX());
            //*********************************************************************
            MainActivity.this.startActivity(item_intent);

        }
    });

What should I use to get the image source from ImageView?

like image 653
Arif YILMAZ Avatar asked Nov 27 '22 22:11

Arif YILMAZ


2 Answers

Use Bundle like

imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();

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


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

image.setImageBitmap(bmp );
like image 164
Bald bcs of IT Avatar answered Dec 15 '22 09:12

Bald bcs of IT


You need to convert drawable into Bitmap using this solution: And then you can pass it to the next activity via intent, because Bitmap class implements Parcelable interface.

like image 22
Geralt_Encore Avatar answered Dec 15 '22 10:12

Geralt_Encore