title: How to use fragments from a grid view?
body: <p>I am trying to make a gallery of images in my app, I have this currently as a grid view then passing to a full image view via ImageAdapter.</p>
  
  <p>The problem is I want to be able to swipe between pictures after clicking from the grid view.</p>
  
  <p>Someone has mentioned I might be able to use fragments to do this but I am new to android development.</p>
  
  <p>Can someone please explain further on how to do this. Thanks</p>
  
  <p>The code I have is:</p>
  
  <pre><code>    public class Marble extends Activity{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.marble);
  
  GridView gridView = (GridView) findViewById(R.id.gridview1);
  
          // Instance of ImageAdapter Class
          gridView.setAdapter(new ImageAdapter1(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(), FullImageActivity1.class);
                  // passing array index
                  i.putExtra("id", position);
                  startActivity(i);
              }
          });
  
      }
  }
  </code></pre>
  
  <p>then</p>
  
  <pre><code>public class FullImageActivity1 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");
          ImageAdapter1 imageAdapter1 = new ImageAdapter1(this);
  
          ImageView imageView = (ImageView) findViewById(R.id.fullimage);
          imageView.setImageResource(imageAdapter1.mThumbIds[position]);
          imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      }
  }
  </code></pre>
  
  <p>and finally:</p>
  
  <pre><code>public class ImageAdapter1 extends BaseAdapter {
      private Context mContext;
  
      // Keep all Images in array
      Integer[] mThumbIds = {
              R.drawable.arabescato, R.drawable.biancocarrara,
              R.drawable.botticinoclassico, R.drawable.calacattaoro,
              R.drawable.cremamarfil, R.drawable.cremavalencia,
              R.drawable.emperadordark, R.drawable.jurabeige,
              R.drawable.neromarquina, R.drawable.perlatoolympo,
              R.drawable.rojoalicante
  
      };
  
      // Constructor
      public ImageAdapter1(Context c){
          mContext = c;
      }
  
      @Override
      public int getCount() {
          return mThumbIds.length;
      }
  
      @Override
      public Object getItem(int position) {
          return mThumbIds[position];
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {         
          ImageView imageView = new ImageView(mContext);
          imageView.setImageResource(mThumbIds[position]);
          imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
          imageView.setLayoutParams(new GridView.LayoutParams(265, 265));
          return imageView;
      }
  
  }
  </code></pre>