title: How to inflate a gridview within a listview in android?
body: <p>So I realised that I cant put other elements into an android gridview and I cant put the gridview into a scrollview, so I attempted to stick a gridview into an android listview with only 1 listview column to see if I could make that work, this was successful, however when I try to inflate the gridview that is inside the list I keep getting a nullpointerexception where I set the actual grid adapter, Is there another way around this hack? </p>
  
  <pre><code>package com.listtest.testit;
  
  import java.util.ArrayList;
  import java.util.List;
  
  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.widget.AbsListView;
  import android.widget.ArrayAdapter;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.AbsListView.OnScrollListener;
  import android.widget.ListView;
  
  public class ListTestActivity extends Activity {
  
  ViewGroup footer;
  LayoutInflater inflater;
  List&lt;String&gt; theStrings = new ArrayList&lt;String&gt;();
  ListAdapter adapter;
  ListView list;
  GridView grid;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      theStrings.add("");
  
      String[] numbers = new String[] { 
              "A", "B", "C", "D", "E",
              "F", "G", "H", "I", "J",
              "K", "L", "M", "N", "O",
              "P", "Q", "R", "S", "T",
              "U", "V", "W", "X", "Y", "Z"};
  
      list = (ListView) findViewById(R.id.list);
  
      inflater = getLayoutInflater();
      footer = (ViewGroup) inflater.inflate(R.layout.footer, list, false);
      list.addFooterView(footer, null, false);
  
      adapter = new ListAdapter(this, theStrings);
      list.setAdapter(adapter);
  
      ArrayAdapter&lt;String&gt; gridAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, numbers);
  
      grid.setAdapter(gridAdapter);
  
      list.setOnScrollListener(new OnScrollListener() {
          public void onScrollStateChanged(AbsListView view, int scrollState) {
              // Do nothing
          }
  
          public void onScroll(AbsListView view, int firstVisibleItem,
                  int visibleItemCount, int totalItemCount) {
  
              final int lastItem = firstVisibleItem + visibleItemCount;
  
              // threshold being indicator if bottom of list is hit
              if (lastItem == totalItemCount) {
  
                  //addMoreToArray();
                  //adapter.notifyDataSetChanged();
              }
          }
      });
  }
  
  public class ListAdapter extends BaseAdapter {
  
      private Activity activity;
      private List&lt;String&gt; data;
      private LayoutInflater inflater=null;
  
  
      public ListAdapter(Activity a, List&lt;String&gt; theStrings) {
          activity = a;
          data=theStrings;
          inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      }
  
      public int getCount() {
          return data.size();
      }
  
      public Object getItem(int position) {
          return position;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          View vi=convertView;
          if(convertView==null)
              vi = inflater.inflate(R.layout.item, null);
  
          grid=(GridView)vi.findViewById(R.id.gridView1);
  
          return vi;
      }
  }
  
  private void addMoreToArray() {
  
      theStrings.add("");
  
  }
  
  }
  </code></pre>