package com.tonicartos.widget.stickygridheaders;

import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;

public class StickyGridHeadersListAdapterWrapper extends BaseAdapter implements StickyGridHeadersBaseAdapter {
    private DataSetObserver mDataSetObserver = new DataSetObserver() {
        @Override
        public void onChanged() {
            notifyDataSetChanged();
        }

        @Override
        public void onInvalidated() {
            notifyDataSetInvalidated();
        }
    };

    private ListAdapter mDelegate;

    public StickyGridHeadersListAdapterWrapper(ListAdapter adapter) {
        mDelegate = adapter;
        adapter.registerDataSetObserver(mDataSetObserver);
    }

    @Override
    public int getCount() {
        return mDelegate.getCount();
    }

    @Override
    public int getCountForHeader(int header) {
        return 0;
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {
        return null;
    }

    @Override
    public Object getItem(int position) {
        return mDelegate.getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return mDelegate.getItemId(position);
    }

    @Override
    public int getItemViewType(int position) {
        return mDelegate.getItemViewType(position);
    }

    @Override
    public int getNumHeaders() {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return mDelegate.getView(position, convertView, parent);
    }

    @Override
    public int getViewTypeCount() {
        return mDelegate.getViewTypeCount();
    }

    @Override
    public boolean hasStableIds() {
        return mDelegate.hasStableIds();
    }

}

@@ -1,8 +1,9 @@
+%0A
 package 
@@ -292,16 +292,24 @@
 plements
+%0A       
  StickyG
@@ -751,16 +751,51 @@
 dapter;%0A
+        if (adapter != null) %7B%0A    
         
@@ -845,16 +845,26 @@
 erver);%0A
+        %7D%0A
     %7D%0A%0A 
@@ -896,32 +896,97 @@
 nt getCount() %7B%0A
+        if (mDelegate == null) %7B%0A            return 0;%0A        %7D%0A
         return m
@@ -1271,32 +1271,100 @@
 int position) %7B%0A
+        if (mDelegate == null) %7B%0A            return null;%0A        %7D%0A
         return m

Fix closed cursor access.