今天會將剩下的 6 個方法講完。
override fun getGroupCount(): Int {
}
override fun getChildrenCount(groupPosition: Int): Int {
}
override fun getGroupId(groupPosition: Int): Long {
}
override fun getChildId(groupPosition: Int, childPosition: Int): Long {
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
}
override fun hasStableIds(): Boolean {
}
getGroupCount getChildrenCount 這兩個沒什麼好多說的,就回傳 list 長度。getGroupId getChildId 這也沒什麼好多說的,就回傳該 ID。
剩下兩個就比較有趣一點isChildSelectable 當希望子項目可以被點擊且有相對應行為,就 retrun true 吧!hasStableIds 就比較特殊一點了,當此方法 return false 時,adapter 會去執行 getGroupId 和 getChildId 並且 只 對有變化的對象去執行 getView ,這對一些在執行 getView 會耗用大量效能的對象來說,可以達到優化效能的效果。