title: How do i Show selected grid image in Full Screen
body: <p>i created a grid view app using a tutorial:</p>
  
  <p><strong>Please see Tutorial Link:</strong> <a href="http://techiedreams.com/android-custom-gridview-scalable-auto-adjusting-col-width/" rel="nofollow">http://techiedreams.com/android-custom-gridview-scalable-auto-adjusting-col-width/</a></p>
  
  <p>and i want to add new feature in it, i want to show selected grid image in new full screen activity.</p>
  
  <p><strong>i tried like this but i got error: read my code:</strong></p>
  
  <p><strong>Error:</strong></p>
  
  <ol>
  <li><p>Description Resource    Path    Location    Type ImageAdapter cannot be
  resolved to a type  AndroidGridLayoutActivity.java  /Copy of TD
  GridView/src/com/td/gridview    line 21 Java Problem</p></li>
  <li><p>Description Resource    Path    Location    Type ImageAdapter cannot be
      resolved to a type  FullImageActivity.java  /Copy of TD
      GridView/src/com/td/gridview    line 20 Java Problem</p></li>
  <li><p>Description Resource    Path    Location    Type The constructor
      MainActivity(FullImageActivity) is
      undefined   FullImageActivity.java  /Copy of TD
      GridView/src/com/td/gridview    line 20 Java Problem</p></li>
  </ol>
  
  <p><strong>My Code This is the original code used from tutorial / see link on top of this post</strong>
  <strong>this is the code from 1st tutorial using only grid view images</strong></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.td.gridview;
  
  import android.app.Activity;
  import android.content.Context;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewGroup.LayoutParams;
  import android.view.ViewTreeObserver;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      private GridView photoGrid;
      private int mPhotoSize, mPhotoSpacing;
      private ImageAdapter imageAdapter;
  
      // Some items to add to the GRID
      private static final String[] CONTENT = new String[] { "Akon", "Justin Bieber", "AlRight", "Big Sean",
              "Britney Spears", "Hilary", "Micheal Buble", "Akon", "Justin Bieber", "AlRight", "Big Sean",
              "Britney Spears", "Hilary", "Micheal Buble", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Britney Spears",
              "Hilary", "Micheal Buble", "Akon", "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary",
              "Micheal Buble" };
      private static final int[] ICONS = new int[] { R.drawable.cover_akon, R.drawable.cover_justin,
              R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary,
              R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin, R.drawable.cover_alright,
              R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb,
              R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon,
              R.drawable.cover_justin, R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney,
              R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin,
              R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary,
              R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin, R.drawable.cover_alright,
              R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb,
              R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon,
              R.drawable.cover_justin, R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney,
              R.drawable.cover_hilary, R.drawable.cover_mb };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // get the photo size and spacing
          mPhotoSize = getResources().getDimensionPixelSize(R.dimen.photo_size);
          mPhotoSpacing = getResources().getDimensionPixelSize(R.dimen.photo_spacing);
  
          // initialize image adapter
          imageAdapter = new ImageAdapter();
  
          photoGrid = (GridView) findViewById(R.id.albumGrid);
  
          // set image adapter to the GridView
          photoGrid.setAdapter(imageAdapter);
  
          // get the view tree observer of the grid and set the height and numcols dynamically
          photoGrid.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  if (imageAdapter.getNumColumns() == 0) {
                      final int numColumns = (int) Math.floor(photoGrid.getWidth() / (mPhotoSize + mPhotoSpacing));
                      if (numColumns &gt; 0) {
                          final int columnWidth = (photoGrid.getWidth() / numColumns) - mPhotoSpacing;
                          imageAdapter.setNumColumns(numColumns);
                          imageAdapter.setItemHeight(columnWidth);
  
                      }
                  }
              }
          });
      }
  
      // ///////// ImageAdapter class /////////////////
      public class ImageAdapter extends BaseAdapter {
          private LayoutInflater mInflater;
          private int mItemHeight = 0;
          private int mNumColumns = 0;
          private RelativeLayout.LayoutParams mImageViewLayoutParams;
  
          public ImageAdapter() {
              mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                      LayoutParams.MATCH_PARENT);
          }
  
          public int getCount() {
              return CONTENT.length;
          }
  
          // set numcols
          public void setNumColumns(int numColumns) {
              mNumColumns = numColumns;
          }
  
          public int getNumColumns() {
              return mNumColumns;
          }
  
          // set photo item height
          public void setItemHeight(int height) {
              if (height == mItemHeight) {
                  return;
              }
              mItemHeight = height;
              mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, mItemHeight);
              notifyDataSetChanged();
          }
  
          public Object getItem(int position) {
              return position;
          }
  
          public long getItemId(int position) {
              return position;
          }
  
          public View getView(final int position, View view, ViewGroup parent) {
  
              if (view == null)
                  view = mInflater.inflate(R.layout.photo_item, null);
  
              ImageView cover = (ImageView) view.findViewById(R.id.cover);
              TextView title = (TextView) view.findViewById(R.id.title);
  
              cover.setLayoutParams(mImageViewLayoutParams);
  
              // Check the height matches our calculated column width
              if (cover.getLayoutParams().height != mItemHeight) {
                  cover.setLayoutParams(mImageViewLayoutParams);
              }
  
              cover.setImageResource(ICONS[position % ICONS.length]);
              title.setText(CONTENT[position % CONTENT.length]);
  
              return view;
          }
      }
  
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;GridView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/albumGrid"
      style="@style/PhotoGrid"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@color/black"
      android:columnWidth="@dimen/photo_size"
      android:horizontalSpacing="@dimen/photo_spacing"
      android:numColumns="auto_fit"
      android:padding="4dp"
      android:scrollbars="none"
      android:stretchMode="columnWidth"
      android:verticalSpacing="@dimen/photo_spacing" /&gt;
  </code></pre>
  
  <p><strong>photo_item.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/album_item"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;ImageView
          android:id="@+id/cover"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/cover"
          android:background="#70000000"
          android:padding="6dp" &gt;
  
          &lt;TextView
              android:id="@+id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:ellipsize="end"
              android:singleLine="true"
              android:textColor="@color/white"
              android:textSize="12sp"
              android:textStyle="bold" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.td.gridview"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.td.gridview.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.td.gridview.AndroidGridLayoutActivity"
              android:label="@string/app_name" &gt;            
          &lt;/activity&gt;
          &lt;activity
              android:name="com.td.gridview.FullImageActivity"
              android:label="@string/app_name" &gt;            
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>This below code i added to show selected grid image in new full screen
  i got this code from this tutorial see link</strong></p>
  
  <p><a href="http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/" rel="nofollow">http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/</a></p>
  
  <p><strong>this is the 2nd tutorial for show selected grid image in new full screen / see under this title "Showing selected grid image in new Activity (Full Screen)" in mid of this tutorial.</strong> </p>
  
  <p><strong>there is two part of this tutorial 1st for basic grid, 2nd for Showing selected grid image in new Activity (Full Screen),</strong> </p>
  
  <p><strong>remember i am using only 2nd part of this tutorial. instead of 1st part of this tutorial i am using 1st tutorial for grid view.</strong></p>
  
  <p><strong>my grid view 1st part from 1st tutorial is good, need help with 2nd tutorial 2nd part Showing selected grid image in new Activity (Full Screen)</strong></p>
  
  <p><strong>full_image.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;ImageView 
              android:id="@+id/full_image_view"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>FullImageActivity.java</strong></p>
  
  <pre><code>package com.td.gridview;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.ImageView;
  
  public class FullImageActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.full_image);
  
          // get intent data
          Intent i = getIntent();
  
          // Selected image id
          int position = i.getExtras().getInt("id");
          ImageAdapter imageAdapter = new ImageAdapter(this);
  
          ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
          imageView.setImageResource(imageAdapter.mThumbIds[position]);
      }
  
  }
  </code></pre>
  
  <p><strong>AndroidGridLayoutActivity.java</strong></p>
  
  <pre><code>package com.td.gridview;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.GridView;
  
  public class AndroidGridLayoutActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          GridView gridView = (GridView) findViewById(R.id.albumGrid);
  
          // Instance of ImageAdapter Class
          gridView.setAdapter(new ImageAdapter(this));
  
          /**
           * On Click event for Single Gridview Item
           * */
          gridView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                      int position, long id) {
  
                  // Sending image id to FullScreenActivity
                  Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
                  // passing array index
                  i.putExtra("id", position);
                  startActivity(i);
              }
          });
      }
  }
  </code></pre>
  
  <p>my programing skills is not good so please help to adjust my code so i can show grid image in new full screen activity.</p>
  
  <p>grid image is working good ( using first tutorial ) but when i put new codes from second tutorial i got problem. i am not getting how to adjust that second tutorial code to show selected grid image in new full screen.</p>
  
  <p>i added AndroidGridLayoutActivity.java, FullImageActivity.java. in manifest.xml after using 2nd tutorial</p>
  
  <p>( please take a look in provided tutorial link so u can understand what actual code is and what i am trying )</p>
  
  <p>please help me here, try to give fair answer not just comment and pass me here &amp; there, because i got stuck here not getting how to adjust "Showing selected grid image in new Activity (Full Screen)" code in my grid view image.</p>
  
  <p>please tell me what i am doing wrong and want to change / adjust in these codes</p>
  
  <p>i hope i provide fair details.</p>
  
  <p><strong>__________________________________________________________________________________</strong></p>
  
  <p><strong>i got my answer it's</strong></p>
  
  <p><strong>After Some Changes My Working code is:</strong></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.td.gridview;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewGroup.LayoutParams;
  import android.view.ViewTreeObserver;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class MainActivity extends Activity {
  
      private GridView photoGrid;
      private int mPhotoSize, mPhotoSpacing;
      private ImageAdapter imageAdapter;
  
      // Some items to add to the GRID
      private static final String[] CONTENT = new String[] { "Akon", "Justin Bieber", "AlRight", "Big Sean",
              "Britney Spears", "Hilary", "Micheal Buble", "Akon", "Justin Bieber", "AlRight", "Big Sean",
              "Britney Spears", "Hilary", "Micheal Buble", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Akon",
              "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary", "Micheal Buble", "Britney Spears",
              "Hilary", "Micheal Buble", "Akon", "Justin Bieber", "AlRight", "Big Sean", "Britney Spears", "Hilary",
              "Micheal Buble" };
      static final int[] ICONS = new int[] { R.drawable.cover_akon, R.drawable.cover_justin,
              R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary,
              R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin, R.drawable.cover_alright,
              R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb,
              R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon,
              R.drawable.cover_justin, R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney,
              R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin,
              R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary,
              R.drawable.cover_mb, R.drawable.cover_akon, R.drawable.cover_justin, R.drawable.cover_alright,
              R.drawable.cover_big_sean, R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb,
              R.drawable.cover_britney, R.drawable.cover_hilary, R.drawable.cover_mb, R.drawable.cover_akon,
              R.drawable.cover_justin, R.drawable.cover_alright, R.drawable.cover_big_sean, R.drawable.cover_britney,
              R.drawable.cover_hilary, R.drawable.cover_mb };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // get the photo size and spacing
          mPhotoSize = getResources().getDimensionPixelSize(R.dimen.photo_size);
          mPhotoSpacing = getResources().getDimensionPixelSize(R.dimen.photo_spacing);
  
          // initialize image adapter
          imageAdapter = new ImageAdapter();
  
          photoGrid = (GridView) findViewById(R.id.albumGrid);
  
          //start sent image to full screen             
  
          /**
           * On Click event for Single Gridview Item
           * */
          photoGrid.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                      int position, long id) {
  
                  // Sending image id to FullScreenActivity
                  Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
                  // passing array index
                  i.putExtra("id", position);
                  startActivity(i);
              }
          });
          //end sent image to full screen
  
          // set image adapter to the GridView
          photoGrid.setAdapter(imageAdapter);
  
          // get the view tree observer of the grid and set the height and numcols dynamically
          photoGrid.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  if (imageAdapter.getNumColumns() == 0) {
                      final int numColumns = (int) Math.floor(photoGrid.getWidth() / (mPhotoSize + mPhotoSpacing));
                      if (numColumns &gt; 0) {
                          final int columnWidth = (photoGrid.getWidth() / numColumns) - mPhotoSpacing;
                          imageAdapter.setNumColumns(numColumns);
                          imageAdapter.setItemHeight(columnWidth);
  
                      }
                  }
              }
          });
      }
  
      // ///////// ImageAdapter class /////////////////
      public class ImageAdapter extends BaseAdapter {
          private LayoutInflater mInflater;
          private int mItemHeight = 0;
          private int mNumColumns = 0;
          private RelativeLayout.LayoutParams mImageViewLayoutParams;
  
          public ImageAdapter() {
              mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                      LayoutParams.MATCH_PARENT);
          }
  
          public int getCount() {
              return CONTENT.length;
          }
  
          // set numcols
          public void setNumColumns(int numColumns) {
              mNumColumns = numColumns;
          }
  
          public int getNumColumns() {
              return mNumColumns;
          }
  
          // set photo item height
          public void setItemHeight(int height) {
              if (height == mItemHeight) {
                  return;
              }
              mItemHeight = height;
              mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, mItemHeight);
              notifyDataSetChanged();
          }
  
          public Object getItem(int position) {
              return position;
          }
  
          public long getItemId(int position) {
              return position;
          }
  
          public View getView(final int position, View view, ViewGroup parent) {
  
              if (view == null)
                  view = mInflater.inflate(R.layout.photo_item, null);
  
              ImageView cover = (ImageView) view.findViewById(R.id.cover);
              TextView title = (TextView) view.findViewById(R.id.title);
  
              cover.setLayoutParams(mImageViewLayoutParams);
  
              // Check the height matches our calculated column width
              if (cover.getLayoutParams().height != mItemHeight) {
                  cover.setLayoutParams(mImageViewLayoutParams);
              }
  
              cover.setImageResource(ICONS[position % ICONS.length]);
              title.setText(CONTENT[position % CONTENT.length]);
  
              return view;
          }
      }
  
  }
  </code></pre>
  
  <p><strong>FullImageActivity.java</strong></p>
  
  <pre><code>package com.td.gridview;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.ImageView;
  
  public class FullImageActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.full_image);
  
          // get intent data
          Intent i = getIntent();
  
          // Selected image id
          int position = i.getExtras().getInt("id");
          ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
          imageView.setImageResource(MainActivity.ICONS[position]);
  
      }
  
  }
  </code></pre>