get BaseAdapter from Adapter - Android User Interface

Android examples for User Interface:Adapter

Description

get BaseAdapter from Adapter

Demo Code


//package com.java2s;
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  va 2 s. c  o m*/
        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