1

I've just finished copying the android walkthrough for the gallery (http://developer.android.com/resources/tutorials/views/hello-gallery.html) and was wondering how I would go about having the thumbnail photo scale into a larger one within the onClickItem method.

        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Toast.makeText(ProjectPreview.this, "" + position, Toast.LENGTH_SHORT).show();
        }

Currently it just shows the position as depicted in the Toast. Could someone point me in the right direction or show me a simple way?

Thanks in advance.

EDIT: Added this method and called it in the onItemClick sending it the position. And it works.

    public void showLarger(int position){
        ImageView image = (ImageView) findViewById(R.id.iv1);
        image.setLayoutParams(new Gallery.LayoutParams(200, 100));
        image.setScaleType(ImageView.ScaleType.FIT_XY);
        image.setImageResource(mImageIds[position]);
    }
Denis
  • 1,201
  • 2
  • 10
  • 11

3 Answers3

0

Use a Dialog with a layout which contains an imageview, and set its source case the position you have and with the size you want.

Vervatovskis
  • 2,277
  • 5
  • 29
  • 46
0

I would use a Dialog. You can create a new activity and have an ImageView in its layout, and disguise that Activity as a Dialog. See this question for how to do all that: Android Image Dialog/Popup

Community
  • 1
  • 1
breadbin
  • 584
  • 1
  • 11
  • 19
0

As mentioned above, you can use a Dialog to display the larger image or you can just fire an intent that would start a regular Activity(You will have to add the dialog Theme to your Activity if you do it as described as above).

You'd have to do something like call v.getItemID(position) and store that in a String, then pass that into your next Activity.

Either way, you'll have to pass in some data to your Activty that will host the ImageView, and then use that data(path, uri, etc) to inflate your larger ImageView. Just don't forget to add the theme to your manifest if you want use the Dialog route.

Jade Byfield
  • 4,668
  • 5
  • 30
  • 41