天天看點

Android中文API (110) —— CursorTreeAdapter

前言

聲明

  歡迎轉載,但請保留文章原始出處:) 

正文

一、結構

public abstract class cusrortreeadapter

         extends baseexpandablelistadpater implements filterable

java.lang.object

android.widget.baseexpandablelistadapter

         android.widget.cursortreeadapter

直接子類

         resourcecursortreeadapter

間接子類

simplecursortreeadapter

  二、概述

  三、構造函數

    public cursortreeadapter (cursor cursor, context context)

           構造函數。每當資料庫的資料發生改變時,擴充卡将調用requery()重新查詢以顯示最新的資料。

                  參數

   cursor       為組(groups)提供資料的遊标(coursor)

                  context    應用程式上下文。

    public cursortreeadapter (cursor cursor, context context, boolean autorequery)

           構造函數。

                   參數

    cursor       為組(groups)提供資料的遊标(coursor)

                   context    應用程式上下文。

                         autorequery 設定為true時,每當資料庫的資料發生改變時,擴充卡将調用requery()重新查詢以顯示最新的資料。

  四、公共方法

  public void changecursor (cursor cursor)

  更改相關的遊标為新傳入的遊标。如果遊标已經存在則先關閉這個已存在的遊标。

  參數

                            cursor               新遊标(cursor)對象。

  public charsequence converttostring (cursor cursor)

  将cursor轉換成charsequence。子類應該重寫這個方法并轉換它們的結果。這個方法的預設實作是:當cursor為空時傳回一個空串,否則直接傳回調用cursor的tostring()方法。

                            cursor               将cursor轉換成charsequence對象。                 

           傳回值

                   傳回charsequence類型的值(譯者注:這個值是通過轉換參數cursor類型而獲得的。)

  public cursor getchild (int groupposition, int childposition)

           擷取指定組中的指定子元素的相關資料。

                            groupposition 組位置(該組内部含有子元素)

                            childposition    子元素位置(相對于其它子元素)

                  傳回值

                            傳回指定子元素資料。

  public long getchildid (int groupposition, int childposition)

                            groupposition 組位置(該組内部含有子元素)

                  子元素關聯id。

           public view getchildview (int groupposition, int childposition, boolean islastchild,  view convertview, viewgroup parent)

  擷取一個視圖對象,顯示指定組中的指定子元素資料。

                            childposition   子元素位置(決定傳回哪個視圖)

                            islastchild    子元素是否處于組中的最後一個

                            parent            傳回的視圖(view)對象始終依附于的視圖組。

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

  public int getchildrencount (int groupposition)

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

                           groupposition 組位置(決定傳回哪個組的子元素個數)

                           傳回組中的子元素個數

  public cursor getcursor ()

           傳回目前擴充卡綁定的cursor對象。

  傳回值

                            cursor對象。

  public filter getfilter ()

           傳回一個可以通過一種過濾模式來限制資料的過濾器。

           這個方法通常在adapter類中實作。

                            傳回一個用來限制資料的過濾器(filter)對象。

  public filterqueryprovider getfilterqueryprovider ()

  傳回一個提供過濾的查詢過濾器。若過濾器為null,則不再過濾。

                            傳回目前過濾器對象,如果不存在傳回null。

                   參考

  public cursor getgroup (int groupposition)

  擷取指定組中的資料

                            groupposition 組位置

                           傳回組中的資料,也就是該組中的子元素資料。

  public int getgroupcount ()

           擷取組的個數

                           組的個數

  public long getgroupid (int groupposition)

                            groupposition  組位置

                            傳回組id

  public view getgroupview (int groupposition, boolean isexpanded, view convertview, viewgroup parent)

      參數

                   groupposition 組位置(決定傳回哪個視圖)

                   isexpanded   該組是展開狀态還是伸縮狀态

                   parent            傳回的視圖對象始終依附于的視圖組。

           傳回值

                   傳回指定組的視圖對象

    public boolean hasstableids ()

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

        傳回值

                            傳回一個boolean類型的值,如果為true,意味着相同的id永遠引用相同的對象。

           public boolean ischildselectable (int groupposition, int childposition)

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

                            childposition  子元素位置

                  是否選中子元素

           public void notifydatasetchanged (boolean releasecursors)

           通知資料集已改變,該方法還為任何帶有緩存功能的遊标提供不用釋放資源的可選功能。

                  releasecursors 是否釋放任何帶有緩沖功能的遊标資源

           public void notifydatasetchanged ()

           該方法内部實作了在每個觀察者上面調用onchanged事件。每當發現資料集有改變的情況,或者讀取到資料的新狀态時,就會調用此方法。

           public void notifydatasetinvalidated ()

           該方法内部實作了在每個觀察者上面調用oninvalidated事件。每當發現資料集監控有改變的情況,比如該資料集不再有效,就會調用此方法。

           public void ongroupcollapsed (int groupposition)

           當指定組收縮狀态的時候調用此方法。

                            groupposition 指定組收縮狀态

  public cursor runqueryonbackgroundthread (charsequence constraint)

        參數

                   constraint 當某個查詢需要過濾功能,使用參數constraint作為限制條件。

                            傳回含有新的查詢結果的cursor。

  參考

    public void setchildrencursor (int groupposition, cursor childrencursor)

    為指定組子元素設定遊标(cursor),并關閉已存在的遊标。這個方法是非常有用的,當進行異步查詢操作的時候用來避免ui發生阻塞的情況。

                  groupposition  組位置(組中的哪個子元素要設定遊标對象)

                        childrencursor 組子元素的遊标(cursor)

    public void setfilterqueryprovider (filterqueryprovider filterqueryprovider)

                   filterqueryprovider  過濾生成器對象,設定為null時,就相當于移除了該生       成器 。

                  參考

    public void setgroupcursor (cursor cursor)

    設定組遊标對象。

                           cursor 設定組遊标對象,并關閉已存在的遊标對象。

  五、受保護方法

    protected abstract void bindchildview (view view, context context, cursor cursor,           boolean islastchild)

    用遊标(coursor)的方式将子元素資料綁定在一個已存在的視圖(view)對象上。

                            view              已存在的視圖(view)對象, 也就是之前new出來的。

                            context          應用程式上下文對象

                            cursor            擷取資料的遊标對象,它已經移動到正确的位置

                            islastchild   子元素是否處于組中的最後一個

    protected abstract void bindgroupview (view view, context context, cursor cursor,        boolean isexpanded)

    用遊标(coursor)的方式将組資料綁定在一個已存在的視圖(view)對象上。

                            view              已存在的組視圖(view)對象, 也就是早先new出來的。

                            context          應用程式上下文對象,它已經移動到正确的位置

                            cursor            擷取資料的遊标對象

                            isexpanded  該組是展開狀态還是伸縮狀态

    protected abstract cursor getchildrencursor (cursor groupcursor)

    擷取指定組中的子元素遊标對象。子類必須實作這個方法,用于在指定組中傳回子元素資料。

                            groupcursor 組遊标對象,決定傳回哪個組中的子元素遊标對象。

                   傳回值

                            傳回指定組中的子元素遊标對象或者為null。

    protected abstract view newchildview (context context, cursor cursor, boolean     islastchild, viewgroup parent)

    建立一個新的子元素視圖并持有指向資料的遊标cursor。

                            islastchild  子元素是否處于組中的最後一個

                            parent     新視圖(view)所依附于的父對象。

    protected abstract view newgroupview (context context, cursor cursor, boolean isexpanded, viewgroup parent)

    建立一個新的組視圖并持有組中指向資料的遊标cursor。

                            isexpanded  該組是否展開狀态

                                parent      新視圖(view)所依附于的父對象。

  六、補充 

         文章精選

  七、公告

    預計翻譯組第五個合集與2011年4月6日釋出,敬請期待!

轉載:http://www.cnblogs.com/over140/archive/2011/03/28/1997551.html