user386430
user386430

Reputation: 4967

How to display selected gallery image in imageview in android

I have image view and gallery in the activity.I am getting the image url from WebService.When user select image in gallery.I have to show correspondace image in ImageView can anybody tell how to do?

Upvotes: 0

Views: 3841

Answers (3)

Eight
Eight

Reputation: 4284

To let the user select a image from gallery you can use ::

Intent intent = new Intent();  
intent.setType("image/*");  
intent.setAction(Intent.ACTION_GET_CONTENT);  
startActivityForResult(Intent.createChooser(intent, "Choose Picture"), requestCode);

once the user selects an Image you can get the URI of the image from onActivityResult(Intent intent) method using uri = intent.getData(), and set this URI to your image view. do imageView.setImageURI(uri).

Upvotes: 2

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

   gallery.setOnItemClickListener(new OnItemClickListener(){   
       @Override
       public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
           Toast.makeText(YourActivity.this,""+position + " Clicked", Toast.LENGTH_LONG).show();
           imageview.setImageDrawable(bitmap_which_is_displayed);//may be from any array or list
           //or
           imageview.setImageBitmap(drawable_which_is_displayed);//may be from any array or list
       } 
   });

Upvotes: 1

Trung Nguyen
Trung Nguyen

Reputation: 7532

You can set onItemClick event for Gallery and pass the id of selected picture to another ImageView or ImageSwitcher. In API demo there's a sample

ImageSwitcher1

and you can check another tutorial here

Upvotes: 1

Related Questions