?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
BaseExpandableListAdapter
譯者博客:http://sd6733531.javaeye.com/
版本:Android 2.3 r1
?
結(jié)構(gòu)
繼承關(guān)系
public abstract class BaseExpandableListAdapter extends Object
implements ExpandableListAdapter, HeterogeneousExpandableList
?
java.lang.Object
android.widget.BaseExpandableListAdapter
?
子類及間接子類
直接子類
???????? ?????? CursorTreeAdapter,SimpleExpandableListAdapter
間接子類
ResourceCursorTreeAdapter, SimpleCursorTreeAdapter
?
類概述
BaseExpandableListAdapter
是
ExpandableListAdapter
的抽象基類,從一些數(shù)據(jù)中提供數(shù)據(jù)和視圖給可折疊列表視圖。
所有繼承本類的Adapters需要保證實現(xiàn)的getCombinedChildId(long,
long)
和 getCombinedGroupId(long)
方法能正確地從View組或View子元素的ID中生成唯一的ID號。
(譯者注:組元素表示可折疊的列表項,子元素表示列表項展開后看到的多個子元素項。由于可折疊列表單純尋找組元素和子元素的ID不是很方便,因此使用聯(lián)合ID的方式來解決。于是有了getCombinedChildId()和getCombinedGroupId()方法。在andorid自帶的ApiDomos的例子中有這個的代碼:App/View/ExpandableList1)。
?
公共方法
public boolean areAllItemsEnabled ()
是否啟用所有元素。
?
public int getChildType (int groupPosition, int childPosition)
獲取由getChildView(int,
int, boolean, View, ViewGroup)
方法創(chuàng)建的指定子元素類型。
參數(shù)
??????????????????????????? groupPosition? 子元素所在的組位置
??????????????????????????? childPosition? 子元素所在的位置
?????????????????? 返回值
??????????????????????????? 0表示任意一個子元素類型,因此此時應(yīng)當(dāng)只聲明一種子元素類型。
?
public?int?getChildTypeCount()
獲取由getChildView(int,
int, boolean, View, ViewGroup)
創(chuàng)建的所有子元素類型個數(shù)。每種類型表示一個能被getChildView(int,
int, boolean, View, ViewGroup)
轉(zhuǎn)換的(任意組中的)View集合。如果適配器總是從所有的子元素中返回同一種類型,本方法將返回1。
本方法將僅僅在AdapterView設(shè)置適配器時被調(diào)用。
?????????????????? 返回值
??????????????????????????? BaseExpandableListAdapter默認(rèn)返回1。
?
public long?getCombinedChildId?(long groupId, long childId)
若你預(yù)見以下默認(rèn)實現(xiàn)的IDs可能出現(xiàn)沖突,請重寫本方法。
實現(xiàn)返回一個long型:
l? 第0位:不管ID指向的是一個子元素(未設(shè)置)還是一個組(已設(shè)置),對于本方法bit值為1.
l? 第1-31位:小于31位的組ID。
l? 第32-63位:小于32位的子元素ID。
從列表所有項(組或子項)中獲得一個唯一的子ID號??烧郫B列表要求每個元素(組或子項)在所有的子元素和組中有一個唯一的ID。本方法負(fù)責(zé)根據(jù)所給的子ID號和組ID號返回唯一的ID。此外,若hasStableIds()
是true,那么必須要返回穩(wěn)定的ID。
?????????????????? 參數(shù)
??????????????????????????? groupID?? 包含該子元素的組ID
??????????????????????????? childID????? 子元素的ID號
?????????????????? 返回
??????????????????????????? 列表所有項(組或子項)中唯一的(和可能穩(wěn)定)的子元素ID號。
?
public long?getCombinedGroupId?(long groupId)
若你預(yù)見以下默認(rèn)實現(xiàn)產(chǎn)生IDs沖突的話,請重寫本方法。
實現(xiàn)返回一個long型:
l? 第0位:不管ID指向的是一個子元素(未設(shè)置)還是一個組(已設(shè)置),對于本方法bit值為1.
l? 第1-31位:小于31位的組ID。
l? 第32-63位:小于32位的子元素ID。
從列表所有項(組或子項)中獲得一個唯一的子ID號??烧郫B列表要求每個元素(組或子項)在所有的子元素和組中有一個唯一的ID。本方法負(fù)責(zé)根據(jù)所給的子ID號和組ID號返回唯一的ID。此外,若hasStableIds()
是true,那么必須要返回穩(wěn)定的ID。
參數(shù)
??????????????????????????? groupID?? 包含該子元素的組ID
?????????????????? 返回
??????????????????????????? 列表所有項(組或子項)中唯一的(和可能穩(wěn)定)的子元素ID號。
?
public int?getGroupType?(int groupPosition)
獲得由getGroupView(int,
boolean, View, ViewGroup)
方法創(chuàng)建的組元素類型。為設(shè)置的組元素。
????
參數(shù)
???????? groupPosition??
應(yīng)返回類型所在組的位置
????
返回
???????? 0
表示任意組位置,因此此時應(yīng)當(dāng)只申明了一種組類型。
?
public int?getGroupTypeCount?()
返回由getGroupView(int, boolean, View, ViewGroup)方法創(chuàng)建的組視圖類型個數(shù)。每個類型表示一個能被getGroupView(int, boolean, View, ViewGroup)轉(zhuǎn)換的View集合。如果適配器總是返回同一種組類型,則此時本方法將返回1.
本方法將僅當(dāng)適配器被AdapterView設(shè)置時調(diào)用。
??????????? 返回
???????????????????? BaseExpandableListAdapter默認(rèn)返回1.
?
public boolean?isEmpty?()
???????? (譯者注:如果適配器沒有任何數(shù)據(jù),返回真。參見Adapter)
?
public void?notifyDataSetChanged?()
(譯者注:當(dāng)后臺數(shù)據(jù)集發(fā)生改變時,調(diào)用此方法響應(yīng)數(shù)據(jù)集的更改。)
參見
notifyChanged()
?
public void?notifyDataSetInvalidated?()
??????????? (譯者注:當(dāng)后臺數(shù)據(jù)集不被驗證的時候,調(diào)用此方法。)
???????
參見
???????????
notifyInvalidated()
?
public void?onGroupCollapsed?(int groupPosition)
當(dāng)組折疊的時候被調(diào)用。
?????????????????? 參數(shù)
??????????????????????????? groupPosition 要折疊的組所在位置
?
public void?onGroupExpanded?(int groupPosition)
當(dāng)組展開的時候被調(diào)用。
?????????????????? 參數(shù)
??????????????????????????? groupPosition 要折疊的組所在位置
?
public void?registerDataSetObserver?(DataSetObserver observer)
(譯者注:注冊當(dāng)用該適配器修改數(shù)據(jù)時調(diào)用的觀察器。)
?
public void?unregisterDataSetObserver?(DataSetObserver?observer)
(譯者注:注銷之前通過 registerDataSetObserver(DataSetObserver)
方法注冊到該適配器的觀察器。)
?
補(bǔ)充
???????? 文章鏈接
?????????????????? Android BaseExpandableListAdapter 教程
?