Android為我們提供了android.widget.Adapter和android.widget.ExpandableListAdapter兩大類資料配接器介面。android.widget.ExpandableListAdapter介面主要和android.widget.ExpandableListView配合使用而android.widget.Adapter介面主要和android.widget.AdapterView中android.widget.ExpandableListView之除外的其他類配合使用。
以下是ExpandableListAdapter介面及子介面和實作類別的關係圖
圖1
ExpandableListAdapter申明的主要介面有:getChild系列和getGroup系列及getCombined系列
實現ExpandableListAdapter的介面:
無
實現ExpandableListAdapter的類有
BaseExpandableListAdapter
CursorTreeAdapter
ResourceCursorTreeAdapter
SimpleCursorTreeAdapter
SimpleExpandableListAdapter
更多請參考《ExpandableListAdapter》一、BaseExpandableListAdapter
BaseExpandableListAdapter實現了介面ExpandableListAdapter
BaseExpandableListAdapter的子類
CursorTreeAdapter
ResourceCursorTreeAdapter
BaseExpandableListAdapter主要實現了ExpandableListAdapter介面的四個方法
getCombinedChildId(long, long)
getCombinedGroupId(long)
onGroupCollapsed(int groupPosition)[空實現]
onGroupExpanded(int groupPosition)[空實現]
更多請參考《BaseExpandableListAdapter》二、CursorTreeAdapter
CursorTreeAdapter繼承於BaseExpandableListAdapter是個虛類。
它為cursor和ExpandableListView提供了串連的橋樑。
CursorTreeAdapter的子類有
CursorTreeAdapter
ResourceCursorTreeAdapter
SimpleCursorTreeAdapter
使用CursorTreeAdapter需要實現五個方法:bindChildView,bindGroupView,getChildrenCursor,newChildView,newGroupView更多請參考《CursorTreeAdapter》三、ResourceCursorTreeAdapter
ResourceCursorTreeAdapter繼承CursorTreeAdapter。
它讓使用者提供Group和child的布局檔案id,
然後實現來自於CursorTreeAdapter的兩個方法(newChildView,newGroupView)來為使用者建立Group和child的View
ResourceCursorTreeAdapter的子類有
SimpleCursorTreeAdapter
ResourceCursorTreeAdapter實現了來自於CursorTreeAdapter的兩個方法:
newChildView,newGroupView
但使用CursorTreeAdapter還需要實現下面三個方法:bindChildView,bindGroupView,getChildrenCursor。
更多可參考《ResourceCursorTreeAdapter》
四、SimpleCursorTreeAdapter
SimpleCursorTreeAdapter繼承於ResourceCursorTreeAdapter。
它為cursor和ExpandableListView提供了串連的橋樑。
它提供把cursor的資料繫結到Group和child的布局檔案中的控制項的功能。綁定的控制項只能是TextView和ImageView
SimpleCursorTreeAdapter沒有子類。
他實現了來自於ResourceCursorTreeAdapter的兩個方法:
bindChildView,bindGroupView
但使用CursorTreeAdapter還需要實現一個方法:getChildrenCursor更多請參考《SimpleCursorTreeAdapter》五、SimpleExpandableListAdapter
SimpleExpandableListAdapter繼承於BaseExpandableListAdapter。
他負責把靜態group資料和child資料對應到XML檔案中定的group和child視圖上。
SimpleExpandableListAdapter無子類。
更多請參考《SimpleExpandableListAdapter》
評論這張轉寄至微博