Enlarge images in grid view - Android development
<p>I'm just getting into Android development and have been following Google's HelloGridView tutorial (http://developer.android.com/guide/topics/ui/layout/gridview.html). I've understood the tutorial and wanted to add an additional function to enlarge a picture of whatever grid is clicked. The code below shows what I've tried so far and I think I'm not getting the correct "imageId" for each grid.</p>

<p>MainActivity.java</p>

<pre><code>import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {

            long imageId = ImageAdapter.getAdapter.getItemId(position);

            Intent fullScreenIntent = new Intent(v.getContext(), FullScreenImage.class);
            fullScreenIntent.putExtra(MainActivity.class.getName(), imageId);

            MainActivity.this.startActivity(fullScreenIntent);
        }
    });
} 
}
</code></pre>

<p>ImageAdapter.java</p>

<pre><code>import android.content.Context;
import android.view.FocusFinder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return mThumbIds[position];
}

// create a new ImageView for each item referenced by the Adapter.
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) { // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// reference to our images
private Integer[] mThumbIds = {
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7
};  
}
</code></pre>

<p>FullScreenImage.java</p>

<pre><code>import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

public class FullScreenImage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image_view);

    Intent intent = getIntent();
    long imageId = (Long) intent.getExtras().get(MainActivity.class.getName());
    ImageView imageView = (ImageView)findViewById(R.id.fullscreenimage);

    imageView.setLayoutParams(new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

    imageView.setImageResource((int)imageId);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);

}   
}
</code></pre>

<p>Also got activity_main.xml with grid view and full_screen_view.xml with ImageView that fills the whole screen.</p>

<p>Any input would be great thanks</p>
