資料配接器簡介(Adapter)

來源:互聯網
上載者:User

Android為我們提供了android.widget.Adapter和android.widget.ExpandableListAdapter兩大類資料配接器介面。android.widget.ExpandableListAdapter介面主要和android.widget.ExpandableListView配合使用而android.widget.Adapter介面主要和android.widget.AdapterView中android.widget.ExpandableListView之除外的其他類配合使用。 

以下是Adapter介面及子介面和實作類別的關係圖圖1:

 

public interface Adapter
Adapter是綁定 Data和AdapterView 的適配器

實現Adapter的直接介面有:ListAdapter和    SpinnerAdapter

更多可參考《Adapter介面》
 一、ListAdapter

ListAdapter是綁定 Data和Listview的適配器。但是,它是介面,需要實現。

實現了ListAdapter的介面有:

    WrapperListAdapter

實現ListAdapter的類:
BaseAdapter
    ArrayAdapter<T>

     CursorAdapter
        ResourceCursorAdapter

            SimpleCursorAdapter
      SimpleAdapter
HeaderViewListAdapter (extends Object)(implements WrapperListAdapter)

    常見的有:arrayAdapter,SimpleAdapter ,CursorAdapter。

    ListAdapter經常和ListView一起使用,具體可參考《ListActivity 和ListView 》

 二、SpinnerAdapter
SpinnerAdapter是綁定 Data和Spinner的適配器.

它只申明了一個方法:

abstract                                                            View                

        getDropDownView(int position, View convertView, ViewGroup parent)                Get a View that displays in the drop down popup the data at the specified position in the data set.
實現了SpinnerAdapter的類:
BaseAdapter
    ArrayAdapter

    CursorAdapter
        ResourceCursorAdapter

            SimpleCursorAdapter

   SimpleAdapter

實現了SpinnerAdapter的介面:

        無

更多可參考《 SpinnerAdapter》 三、BaseAdapte

    關於BaseAdapte請參考《 BaseAdapter》 四、ArrayAdapter
    ArrayAdapter(數組適配器)的作用就是一個數組和listview之間的橋樑,它可以將數組裡邊定義的資料一一對應的顯示在Listview裡邊。

    ListView的每個 TextView裡邊顯示的內容就是數組裡邊的對象調用toString()方法後產生的字串。

       更多請參考《 ArrayAdapter
 五、SimpleAdapter

        SimpleAdapter是ArrayList和 ListView的橋樑。這個ArrayList裡邊的每一項都是一個Map<String,?>類型。

        ArrayList當中的每一項 Map對象都和ListView裡邊的每一項進行資料繫結一一對應。

        更多請參考《 SimpleAdapter》六、CursorAdapter
            CursorAdapter是個虛類,繼承於BaseAdapter。

   它有兩個虛方法newView和bindView 
            直接子類只有ResourceCursorAdapter
     間接子類只有SimpleCursorAdapter(它繼承於ResourceCursorAdapter)。

   更多請參考《 CursorAdapter
七、ResourceCursorAdapter
    ResourceCursorAdapter是個虛類,它繼承於CursorAdapter。

    它實現了newView,但仍然沒有實現bindView            

    直接子類只有SimpleCursorAdapter,無間接子類。

     更多請參考《 ResourceCursorAdapter
八、SimpleCursorAdapter

    SimpleCursorAdapter繼承於CursorAdapter。它不是虛類,已經實現了bindView。

     更多請參考《 SimpleCursorAdapter》九、WrapperListAdapter
    WrapperListAdapter 擴充了ListAdapter介面

    實現了WrapperListAdapter介面的類只有:HeaderViewListAdapter
    WrapperListAdapter只聲明了一個方法:
    public abstract ListAdapter getWrappedAdapter ()
十、HeaderViewListAdapter

    HeaderViewListAdapter實現了WrapperListAdapter介面,並實現了getWrappedAdapter方法。

    更多請參考《 HeaderViewListAdapter

 評論這張轉寄至微博

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.