title: Android GridView with Both Horizontal and Vertical Scrolbars at the same time
body: <p>I am new to Android and Have to Port a Windows Mobile Application to an Android Application.</p>
  
  <p><strong>Issue:</strong> I need GridView in Android similar to .net GridView which is able to scroll in both Horizontal and Vertical directions at the same time. </p>
  
  <p>As there are many rows and many columns in my data. So, all the columns are not shown as screen width is small on mobile. Multiple rows are shown as vertical scroll is enabled. What i want is that this GridView is somehow <strong><em>scrollable in both directions at the same time</em></strong>. So that user could view data in <strong><em>tabular form</em></strong>.</p>
  
  <p>I am using GridView in Android with the help of TableLayout and SimpleAdapter. Following is my code:</p>
  
  <p><strong>Main Activity Layout:</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
  &lt;!-- This Table Layout is header followed by the gridview --&gt;
  &lt;TableLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="5dp" &gt;
  
      &lt;TableRow android:layout_width="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/schemeTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="Scheme"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/nameTitle"
              android:layout_width="200dp"
              android:layout_height="wrap_content"
              android:text="Name"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/productTitle"
              android:layout_width="200dp"
              android:layout_height="wrap_content"
              android:text="Product"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/channelTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="Channel"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/typeTitle"
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:text="Type"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/customerSelectionTitle"
              android:layout_width="150dp"
              android:layout_height="wrap_content"
              android:text="Customer Selection"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/brandTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="Brand"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/wsTitle"
              android:layout_width="50dp"
              android:layout_height="wrap_content"
              android:text="W/S"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/startDateTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="Start Date"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/endDateTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="End Date"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/codeTitle"
              android:layout_width="80dp"
              android:layout_height="wrap_content"
              android:text="Code"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/tsidTitle"
              android:layout_width="50dp"
              android:layout_height="wrap_content"
              android:text="TSID"
              android:textStyle="bold" /&gt;
      &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  
  &lt;GridView
      android:id="@+id/schemeGridView"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:clickable="true"
      android:numColumns="1"
      android:columnWidth="900dp" &gt;
  &lt;/GridView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Grid Layout:</strong></p>
  
  <pre><code>&lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent" &gt;
  
  &lt;TableRow android:layout_width="wrap_content" &gt;
  
      &lt;TextView
          android:id="@+id/scheme"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/name"
          android:layout_width="200dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/product"
          android:layout_width="200dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/channel"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/type"
          android:layout_width="100dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/customerSelection"
          android:layout_width="150dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/brand"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/ws"
          android:layout_width="50dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/startDate"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/endDate"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/code"
          android:layout_width="80dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/tsid"
          android:layout_width="50dp"
          android:layout_height="wrap_content" /&gt;
  &lt;/TableRow&gt;
  
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p><strong>Source Code:</strong></p>
  
  <pre><code>public class Schemes extends BaseMainActivity {
  
  private String obID = "";
  private String obName = "";
  ArrayList&lt;HashMap&lt;String, Object&gt;&gt; dtSchemes = null;
  GridView schemeGridView = null;
  Activity thisAct = this;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.schemes);
  
      ProgressDialog d = ProgressDialog.show(this, "Inventory",
              "Loading Inventory...");
  
      OrderBookingDAL dl = new OrderBookingDAL();
      obID = dl.getConfigValue("OBID");
      obName = dl.getConfigValue("OBName");
      dtSchemes = dl.getHHTSchemes(obID, obName, dtSchemes);
  
      schemeGridView = (GridView) findViewById(R.id.schemeGridView);
  
      SimpleAdapter sa = new SimpleAdapter(this, dtSchemes,
              R.layout.schemes_grid, new String[] { "Scheme", "Name",
                      "Product", "Channel", "Type", "CustomerSelection",
                      "Brand", "[W/S Approved]", "[Start Date]",
                      "[End Date]", "Code", "TSID" }, new int[] {
                      R.id.scheme, R.id.name, R.id.product, R.id.channel,
                      R.id.type, R.id.customerSelection, R.id.brand, R.id.ws,
                      R.id.startDate, R.id.endDate, R.id.code, R.id.tsid });
      schemeGridView.setAdapter(sa);
      schemeGridView.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
              Log.d("Grid Item Click", "Clicked pos:"+position);
              TextView txt = (TextView) view.findViewById(R.id.tsid);
              if (txt != null &amp;&amp; txt.getText() != null) {
                  String tsid = txt.getText().toString();
                  Intent intent = new Intent(thisAct,SchemeDetails.class); 
                  intent.putExtra(TSID_PARAM, tsid);
                  thisAct.startActivity(intent);
              }
          }
      });
      d.dismiss();
  }
  }
  </code></pre>