title: GridView inside a Fragment: getView is never called
body: <p>I have an <code>Activity</code> with a layout made of two <code>Fragment</code>. One of the fragments layout contains a <code>GridView</code>.</p>
  
  <pre><code>public class PicturesGallery extends FragmentActivity {
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.gallery_frames);
  
          Fragment galleryFragment = fm.findFragmentById(R.id.gallery_fragment);
          if (galleryFragment == null) {
             fm.beginTransaction().add(R.id.gallery_fragment, new GalleryFragment()).commit();
          }
          ...
  </code></pre>
  
  <p>When this fragment is called it instantiates the adapter for the <code>GridView</code>, inflates the <code>GridView</code> and sets the adapter (which has been fed with an <code>ArrayList</code> with 15 items to be displayed).</p>
  
  <pre><code>public class GalleryFragment extends Fragment {
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          // Initialize the layout Adapter
          PicturesGallery pga = (PicturesGallery) getActivity();
          mAdapter = new ImageAdapter(pga.getApplication(), pga.mMemoryCache,
                  galleryDir);
          mAdapter.mPictureNames = new ArrayList&lt;String&gt;(pictureNames);
  
          // Inflate the layout and set the adapter
          LayoutInflater inflater = (LayoutInflater) getActivity()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          GridView gridView = (GridView) inflater.inflate(R.layout.pictures_gallery_fragment, null);
          gridView.setAdapter(mAdapter);
      }
      ....
  </code></pre>
  
  <p>But when the activity is executed nothing happens (no errors in the logcat but nothing displayed on the <code>GridView</code>). In the adapter class, using <code>Log.d()</code> inside <code>getView()</code> indicates that the method is never called. However <code>getCount()</code> returns the right number of items. The relevant code follows.</p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
      ...
      public ArrayList&lt;String&gt; mPictureNames = new ArrayList&lt;String&gt;();
      public ImageAdapter(Context c, LruCache&lt;String, Bitmap&gt; mCache, File gallery) {
          mMemoryCache = mCache;
          mGalleryDir = gallery;
          mInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          Log.d("dupa", "getView");
          ViewHolder vh;
          View cell = convertView;
          if (cell == null) {
              vh = new ViewHolder();
              cell = mInflater.inflate(R.layout.galleryitem, null);
              // Populate the ViewHolder
              vh.checkBox = (CheckBox) cell.findViewById(R.id.itemCheckBox);
              ...
              cell.setTag(vh);
              ...
          } else {
              vh = (ViewHolder) cell.getTag();
          }
          // Update the cell View state
          vh.checkBox.setTag(position);
          ...
          return cell;
      }
  </code></pre>
  
  <p>I've not included xml files because the post is lengthy. If you think they are needed (or you need more code) just tell me. Any help will be greatly appreciated. TIA.</p>