Move One Image From One Activity To Another Activity In Android On Selecting Gridview
Solution 1:
*when you click a image get the paht/uri of that image and create intent and put the value with intent and get it in another activity and show it.
ex:
gridview.setOnItemClickListener(new OnItemClickListener() {
publicvoidonItemClick(AdapterView<?> parent, View v, int position, long id){
int i=R.drawable.ic_launcher;
Intent intent = newIntent(SamaaActivity.this,kl.class);
intent.putExtra("intVariableName", i);
startActivity(intent);
}
});
and get this on other activity
IntentmIntent= getIntent();
intintValue= mIntent.getIntExtra("intVariableName", 0);
Solution 2:
you can get image id when select item and pass id to second activity and retrieve image based on that or you can pass image from one to second using static
variable with Bitmap
so when it get select just display those image easily
Solution 3:
You can also pass the uri of the image as extras in the intent used to invoke the second activity. This way you will avoid decoding the data until the point you really need it.
Solution 4:
Bitmap already implements Parcelable, simply put your bitmap into intent and pass it to next activity.
gridview.setOnItemClickListener(newOnItemClickListener() {
publicvoidonItemClick(AdapterView<?> parent, View v, int position, long id) {
Bitmapimage= imageAdapter.getItem(position);
Intentintent=newIntent(getBaseContext(), NextActivity.class);
intent.putExtra("details", image);
startActivity(intent);
}
});
UPDATE: Better to change your ImageAdapter.getItem() implementation to return a ImageView or Bitmap, to convert imageView to Bitmap, simply do this:
BitmapDrawabledrawable= (BitmapDrawable) imageView.getDrawable();
Bitmapbitmap= drawable.getBitmap();
To retrieve Bitmap from NextActivity:
Parcelabledetails= getIntent().getExtras().getParcelable("details");
Bitmapbitmap= (Bitmap) details;
Post a Comment for "Move One Image From One Activity To Another Activity In Android On Selecting Gridview"