title: Android Programming ViewPager from a GridView
body: <p>I am new to android programming and am looking to implement a gallery which has a grid view that then pushes on to a view pager but I am having a few problems getting this to work.  I have it working currently just using a static Image Adapter but am not sure how to change this to use a view pager instead. I also want to be able to add my own titles to each screen but I wasn't sure how to do this or whether it had to be the image name that would appear?</p>
  
  <p>The code I have at the moment is...</p>
  
  <p>the .xml with the grid view</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#3d3d3e" &gt;
  
      &lt;GridView
          android:id="@+id/gridview1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_above="@+id/phone"
          android:columnWidth="90dp"
          android:gravity="center"
          android:horizontalSpacing="10dp"
          android:numColumns="3"
          android:stretchMode="columnWidth"
          android:verticalSpacing="10dp" &gt;
  &lt;/GridView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>the grid view .java</p>
  
  <pre><code>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 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>the image adapter .java</p>
  
  <pre><code>import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  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>
  
  <p>and finally the image activity .java</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.ImageView;
  
  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>All help on this will be massively appreciated as I'm absolutely stumped!</p>
  
  <p>Thanks in advance!</p>