package z.hol.loadingstate;

import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.ListAdapter;

public class AdapterViewWithLoadingState <T extends AbsListView> extends BaseLoadingStateLayout<T>{
    
    private ListAdapter mAdapter;
    private EmptyDataObserver mEmptyObserver;

    public AdapterViewWithLoadingState(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public AdapterViewWithLoadingState(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public AdapterViewWithLoadingState(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }
    
    public void setAdapter(ListAdapter adapter){
        if (mEmptyObserver == null){
            mEmptyObserver = new EmptyDataObserver();
        }
        if (mAdapter != null){
            mAdapter.unregisterDataSetObserver(mEmptyObserver);
        }
        mAdapter = adapter;
        if (mAdapter != null && isAutoShowEmpty()){
            mAdapter.registerDataSetObserver(mEmptyObserver);
            if (mAdapter.isEmpty()){
                empty();
            }
        }
        mDataView.setAdapter(adapter);
    }
    
    public boolean isDataEmpty(){
        if (mAdapter != null){
            return mAdapter.isEmpty();
        }
        return true;
    }
    
    private class EmptyDataObserver extends DataSetObserver{

        @Override
        public void onChanged() {
            // TODO Auto-generated method stub
            super.onChanged();
            if (mAdapter == null || mAdapter.isEmpty()){
                empty();
            }else{
                hideEmpty();
            }
        }

        @Override
        public void onInvalidated() {
            // TODO Auto-generated method stub
            super.onInvalidated();
        }
    }
}

@@ -2051,24 +2051,168 @@
 alidated();%0A
+            if (mAdapter == null %7C%7C mAdapter.isEmpty())%7B%0A                empty();%0A            %7Delse%7B%0A                hideEmpty();%0A            %7D%0A
         %7D%0A  

Add auto empty on invalid