Reputation: 5866
I am trying to send an image from one activity to another but I dont know how to set the imageview.
here is how I send the image and other stuff
Intent item_intent = new Intent(MainActivity.this, Item.class);
item_intent.putExtra("name","test name arif");
item_intent.putExtra("quantity","99");
//*************************here is the image***************************
item_intent.putExtra("image",R.drawable.access);
MainActivity.this.startActivity(item_intent);
here is how I am trying to read the image and set it to the ImageView but I am getting a syntax error.
Intent intent = getIntent();
ImageView img_view = (ImageView) findViewById(R.id.item_image);
// this where I am having problem below******************************
img_view.setImageBitmap(intent.getByteArrayExtra("image"));
how should I set the ImageView?
Upvotes: 0
Views: 332
Reputation: 892
use this code for get intent
Intent intent = getIntent();
ImageView img_view = (ImageView) findViewById(R.id.item_image);
img_view.setBackgroundResource(intent.getIntExtra("name",1));
Upvotes: 0
Reputation: 28093
Dont you think
img_view.setImageBitmap(intent.getByteArrayExtra("quantity"));
should be
img_view.setImageResource(intent.getIntExtra("name",R.drawable.default_image));
Upvotes: 4