get BaseAdapter from Adapter - Android android.widget

Android examples for android.widget:Adapter

Description

get BaseAdapter from Adapter

Demo Code

import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.HeaderViewListAdapter;

public class Main{

    public static BaseAdapter getAdapter(Adapter adapter) {
        if (adapter == null) {
            return null;
        }//from   w  w  w  .  j a v  a  2  s. c om
        BaseAdapter baseAdapter = null;
        if (adapter instanceof BaseAdapter) {
            baseAdapter = (BaseAdapter) adapter;
        } else if (adapter instanceof HeaderViewListAdapter) {
            HeaderViewListAdapter headerViewAdapter = (HeaderViewListAdapter) adapter;
            if (headerViewAdapter.getWrappedAdapter() instanceof BaseAdapter) {
                baseAdapter = (BaseAdapter) headerViewAdapter
                        .getWrappedAdapter();
            }
        }

        return baseAdapter;
    }

}

Related Tutorials