Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發實例 >> Android 3.0 r1 API中文文檔(108) —— ExpandableListAdapter

Android 3.0 r1 API中文文檔(108) —— ExpandableListAdapter

編輯:Android開發實例

前言

  本章內容是android.widget.ExpandableListAdapter,版本為Android 3.0 r1,翻譯來自"深夜未眠"。
 

 

 

正文

  一、結構

 

public interface ExpandableListAdapter

 

android.widget.ExpandableListAdapter

 

間接子類        

      BaseExpandableListAdapter,CursorTreeAdapter,ResourceCursorTreeAdapter, SimpleCursorTreeAdapter, SimpleExpandableListAdapter

 

 

  二、概述

 

    這個適配器在ExpandableListView和底層數據之間起到了一個銜接的作用。該接口的實現類提供了訪問子元素(以組的形式將它們分類)的數據;同樣,也提供了為子元素和組創建相應的視圖。

 

 

  三、公共方法

 

    public abstract boolean areAllItemsEnabled ()

    ExpandableListAdapter裡面的所有條目都可用嗎?如果是yes,就意味著所有條目可以選擇和點擊了。

  返回值

                   返回True表示所有條目均可用。

      參見

                       areAllItemsEnabled()

 

  public abstract Cursor getChild (int groupPosition, int childPosition)

    獲取指定組中的指定子元素數據。

                  參數

                            groupPosition           組位置(該組內部含有子元素)

                            childPosition              子元素位置(相對於其它子元素)

                  返回值

                            返回指定子元素數據。

 

  public abstract long getChildId (int groupPosition, int childPosition)

  獲取指定組中的指定子元素ID,這個ID在組裡一定是唯一的。聯合ID(參見getCombinedChildId(long, long))在所有條目(所有組和所有元素)中也是唯一的。

                  參數

                            groupPosition           組位置(該組內部含有子元素)

                            childPosition              子元素位置(相對於其它子元素)

                  返回值

                  子元素關聯ID。

 

           public abstract View getChildView (int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)

           獲取一個視圖對象,顯示指定組中的指定子元素數據。

                    參數

                           groupPosition  組位置(該組內部含有子元素)

                            childPosition   子元素位置(決定返回哪個視圖)

                            isLastChild    子元素是否處於組中的最後一個

    convertView   重用已有的視圖(View)對象。注意:在使用前你應該檢查一下這個視圖對象是否非空並且這個對象的類型是否合適。由此引伸出,如果該對象不能被轉換並顯示正確的數據,這個方法就會調用getChildView(int, int, boolean, View, ViewGroup)來創建一個視圖(View)對象。

                            parent              返回的視圖(View)對象始終依附於的視圖組。

                  返回值

                           指定位置上的子元素返回的視圖對象

 

  public abstract int getChildrenCount (int groupPosition)

    獲取指定組中的子元素個數

                  參數

                           groupPosition 組位置(決定返回哪個組的子元素個數)

                  返回值

                           指定組的子元素個數

 

  public abstract long getCombinedChildId (long groupId, long childId)

  從列表所有項(組或子項)中獲得一個唯一的子ID號。可折疊列表要求每個元素(組或子項)在所有的子元素和組中有一個唯一的ID。本方法負責根據所給的子ID號和組ID號返回唯一的ID。此外,若hasStableIds()是true,那麼必須要返回穩定的ID。

                   參數

                            groupId 包含該子元素的組ID

                            childId  子元素的ID

  返回值

  列表所有項(組或子項)中唯一的(和可能穩定)的子元素ID號。(譯者注:ID理論上是穩定的,不會發生沖突的情況。也就是說,這個列表會有組、子元素,它們的ID都是唯一的。)

 

  public abstract Cursor getGroup (int groupPosition)

  獲取指定組中的數據

                  參數

                            groupPosition 組位置

                  返回值

                           返回組中的數據,也就是該組中的子元素數據。

 

  public abstract int getGroupCount ()

    獲取組的個數

                  返回值

                           組的個數

 

    public abstract long getGroupId (int groupPosition)

  獲取指定組的ID,這個組ID必須是唯一的。聯合ID(參見getCombinedGroupId(long))在所有條目(所有組和所有元素)中也是唯一的。

                  參數

                            groupPosition 組位置

                  返回值

                            返回組相關ID

 

  public abstract View getGroupView (int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)

    獲取顯示指定組的視圖對象。這個方法僅返回關於組的視圖對象,要想獲取子元素的視圖對象,就需要調用getChildView(int, int, boolean, View, ViewGroup)

      參數

                   groupPosition 組位置(決定返回哪個視圖)

                   isExpanded    該組是展開狀態還是伸縮狀態

    convertView  重用已有的視圖對象。注意:在使用前你應該檢查一下這個視圖對象是否非空並且這個對象的類型是否合適。由此引伸出,如果該對象不能被轉換並顯示正確的數據,這個方法就會調用getGroupView(int, boolean, View, ViewGroup)來創建一個視圖(View)對象。

                      parent            返回的視圖對象始終依附於的視圖組。

           返回值

                     返回指定組的視圖對象

 

           public abstract boolean hasStableIds ()

           組和子元素是否持有穩定的ID,也就是底層數據的改變不會影響到它們。

           返回值

    返回一個Boolean類型的值,如果為TRUE,意味著相同的ID永遠引用相同的對象。

 

           public abstract boolean isChildSelectable (int groupPosition, int childPosition)

           是否選中指定位置上的子元素。

                    參數

                           groupPosition 組位置(該組內部含有這個子元素)

                           childPosition  子元素位置

                    返回值

                    是否選中子元素

 

    public abstract boolean isEmpty ()

             返回值

  如果當前適配器不包含任何數據則返回True。經常用來決定一個空視圖是否應該被顯示。一個典型的實現將返回表達式getCount() == 0的結果,但是由於getCount()包含了頭部和尾部,適配器可能需要不同的行為。

                 參見

                          isEmpty()

 

    public abstract void onGroupCollapsed (int groupPosition)

    當組收縮狀態的時候此方法被調用。

                  參數

                            groupPosition 收縮狀態的組索引

 

    public abstract void onGroupExpanded (int groupPosition)

    當組展開狀態的時候此方法被調用。

                   參數

                            groupPosition 展開狀態的組位置

 

    public abstract void registerDataSetObserver (DataSetObserver observer)

    注冊一個觀察者(observer),當此適配器數據修改時即調用此觀察者。

                  參數

                            observer 當數據修改時通知調用的對象。

 

    public abstract void unregisterDataSetObserver (DataSetObserver observer)

  取消先前通過registerDataSetObserver(DataSetObserver)方式注冊進該適配器中的觀         察者對象。

                  參數

                              observer  取消這個觀察者的注冊

 

 

  四、補充

 

           文章精選

                   android 可展開(收縮)的列表ListView(ExpandableListView)

                   android CursorAdapter的監聽事件

 


 

 

ExpandableListView.OnChildClickListener

譯者署名: 情敵貝多芬

譯者鏈接:http://liubey.javaeye.com/

版本:Android 3.0 r1

結構

繼承關系

public static interface ExpandableListView.OnChildClickListener

 

java.lang.Object

android.widget.ExpandableListView.OnChildClickListener

 

子類及間接子類

間接子類

ExpandableListActivity

 

類概述

這是一個定義了當可折疊列表(expandable list)裡的子元素(child)發生點擊事件時調用的回調方法的接口。

 

公共方法

public abstract boolean onChildClick (ExpandableListView parent, View v, int groupPosition, int childPosition, long id)

  用當可折疊列表裡的子元素(child)被點擊的時候被調用的回調方法。

參數

             parent                    發生點擊動作的ExpandableListView

                 v                    在expandable list/ListView中被點擊的視圖(View)

                 groupPosition                   包含被點擊子元素的組(group)在ExpandableListView中的位置(索引)

                 childPosition                   被點擊子元素(child)在組(group)中的位置

                 id                  被點擊子元素(child)的行ID(索引)

    返回值

                            當點擊事件被處理時返回true

 

 

 

 

ExpandableListView.OnGroupClickListener

譯者署名: 情敵貝多芬

譯者鏈接:http://liubey.javaeye.com/

版本:Android 3.0 r1

結構

繼承關系

public static interface ExpandableListView.OnGroupClickListener

 

java.lang.Object

android.widget.ExpandableListView.OnGroupClickListener

 

類概述

這是一個定義了當可折疊列表(expandable list)裡的組(group)發生點擊事件時調用的回調方法的接口。

 

公共方法

public abstract boolean onGroupClick (ExpandableListView parent, View v, int groupPosition, long id)

  用當可折疊列表裡的組(group)被點擊的時候被調用的回調方法。

參數

      parent            發生點擊事件的ExpandableListConnector

      v                    在expandable list/ListView中被點擊的視圖(View)

      groupPosition  被點擊的組(group)在ExpandableListConnector中的位置(索引)

      id                   被點擊的組(group)的行ID(索引)

    返回值

      當點擊事件被處理的時候返回true

 

 

 

 

ExpandableListView.OnGroupCollapseListener

譯者署名: 深夜未眠

譯者鏈接:http://chris1012f.javaeye.com/

版本:Android 3.0 r1

結構

繼承關系

public interface ExpandableListView.OnGroupCollapseListener

         java.lang.Object

         android.widget.ExpandableListView.OnGroupCollapseListener

 

子類及間接子類

間接子類

  ExpandableListActivity

 

類概述

         當收縮某個組時,就會發出通知。

 

公共方法

       public abstract void onGroupCollapse (int groupPosition)

         每當收縮當前可伸縮列表中的某個組時,就調用該方法。

                   參數

                            groupPosition 組位置,也就是收縮的那個組的位置。

 

 

 

ExpandableListView.OnGroupExpandListener

譯者署名: 深夜未眠

譯者鏈接:http://chris1012f.javaeye.com/

版本:Android 3.0 r1

結構

繼承關系

public interface ExpandableListView.OnGroupExpandListener

         java.lang.Object

         android.widget.ExpandableListView.OnGroupExpandListener

 

子類及間接子類

間接子類

  ExpandableListActivity

 

類概述

         當展開某個組時,就會發出通知。

 

公共方法

  public abstract void onGroupExpand (int groupPosition)

  每當展開當前可伸縮列表中的某個組時,就調用該方法。

    參數

                            groupPosition 組位置,也就是展開的那個組的位置。

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved