title: Display Empty View in Android Gallery
body: <p>Folks -</p>
  
  <p>I'm trying to implement a Gallery widget that displays an ArrayList of images, and I have started with the <a href="http://developer.android.com/guide/tutorials/views/hello-gallery.html" rel="nofollow noreferrer">Hello, Gallery example</a> on the dev site.  This part is all working great.</p>
  
  <p>I need to have the gallery display an empty view (a special view when the ArrayList has no contents), but I cannot seem to get the Gallery to do this.  I have done this with ListView and other AdapterViews in the past, but I cannot get it to work with Gallery.  What do I need to override/implement in the Adapter, Gallery, or both to get an empty view displayed?  This is my adapter code:</p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
  
       int mGalleryItemBackground;
       private Context mContext;
       private ArrayList&lt;Drawable&gt; images;
  
       public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
        mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
        a.recycle();
  
        images = new ArrayList&lt;Drawable&gt;();
       }
  
       public void addImage(Drawable d) {
        images.add(d);
       }
  
       public boolean isEmpty() {
        return getCount() == 0;
       }
  
       public int getCount() {
        return images.size();
       }
  
       public Drawable getItem(int position) {
        return images.get(position);
       }
  
       public long getItemId(int position) {
        return position;
       }
  
       public View getView(int position, View contentView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);
        i.setImageDrawable(images.get(position));
  
        i.setLayoutParams(new Gallery.LayoutParams(160, 120));
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setBackgroundResource(mGalleryItemBackground);
  
        return i;
       }
  }
  </code></pre>
  
  <p>When the view is to be displayed with an empty ArrayList, getCount() does get called (returning 0), but the Gallery never checks isEmpty, and when I had defined <code>getEmptyView()</code> in the Gallery, it was never called either.  Did I miss another required method in BaseAdapter to properly notify the empty state?</p>
  
  <p>Thanks!</p>