天天看點

Android中文API (109) —— SimpleCursorTreeAdapter

一、結構

public abstract class SimpleCusrorTreeAdapter extends     

ResourceCusorTreeAdpater

java.lang.Object

android.widget.BaseExpandableListAdapter

         android.widget.CursorTreeAdapter

                            android.widget.ResourceCusorTreeAdapter

                                     android.widget.SimpleCursorTreeAdapter

二、概述

三、内部類

    public interface SimpleCursorTreeAdapter.ViewBinder

    這個内部接口可以在外部通過SimpleCursorTreeAdapter.ViewBinder的方式進行 Cursor與View的綁定。

四、構造函數

  public SimpleCursorTreeAdapter (Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, int lastChildLayout, String[] childFrom, int[] childTo)

  構造函數。

                  參數

                            context    上下文,多指ExpandableListView的上下文

                            cursor       資料庫遊标

    collapsedGroupLayout     布局資源檔案辨別ID,其定義的是收縮時的ExpandableListView布局樣式,并且内部至少要包含參數“groupTo”中指定的視圖ID。

    expandedGroupLayout    布局資源檔案辨別ID,其定義的是展開時的ExpandableListView布局樣式,并且内部至少要包含參數“groupTo”中指定的視圖ID。

                            groupFrom       列名清單,顯示ExpandableListView的組節點。

    groupTo             展示參數“groupFrom”中的列,也就是說ExpandableListView中的視圖顯示的是參數 “groupFrom”的列值,它們應該都是TextView或是ImageView。

    childLayout       布局資源檔案辨別ID,其定義的是子視圖的布局樣式 (不包括最後一個子視圖),内部至少要包含參數 “childTo”中指定的視圖ID。lastChildLayout布局資源檔案辨別ID,其定義的是最後一個子視圖的布局樣式,内部至少要包含參數“childTo”中指定的視圖ID。

    lastChildLayout      布局資源檔案辨別ID,其定義的是最後一個子視圖的布局樣式,内部至少要包含參數“childTo”中指定的視圖ID。lastChildLayout布局資源檔案辨別ID,其定義的是最後一個子視圖的布局樣式,内部至少要包含參數“childTo”中指定的視圖ID。

                            childFrom          列名清單,顯示ExpandableListView的子節點。

    childTo             展示參數“childFrom ”中的列,也就是說ExpandableListView中的視圖顯示的是參數 “childFrom ”的列值,它們應該都是TextView或是ImageView。

  public SimpleCursorTreeAdapter (Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)

  構造函數。(譯者注:該構造函數隻是少了一個參數lastChildLayout)

        參數

  context    上下文,多指ExpandableListView的上下文

                       cursor       資料庫遊标

  collapsedGroupLayout     布局資源檔案辨別ID,其定義的是收縮時的ExpandableListView布局樣式,并且内部至少要包含參數“groupTo”中指定的視圖ID。

  expandedGroupLayout    布局資源檔案辨別ID,其定義的是展開時的ExpandableListView布局樣式,并且内部至少要包含參數“groupTo”中指定的視圖ID。

  groupTo             展示參數“groupFrom”中的列,也就是說ExpandableListView中的視圖顯示的是參數 “groupFrom”的列值,它們應該都是TextView或是ImageView。

  childLayout       布局資源檔案辨別ID,其定義的是子視圖的布局樣式 (不包括最後一個子視圖),内部至少要包含參數 “childTo”中指定的視圖ID。lastChildLayout布局資源檔案辨別ID,其定義的是最後一個子視圖的布局樣式,内部至少要包含參數“childTo”中指定的視圖ID。

  childFrom          列名清單,顯示ExpandableListView的子節點。

  childTo             展示參數“childFrom ”中的列,也就是說ExpandableListView中的視圖顯示的是參數 “childFrom ”的列值,它們應該都是TextView或是ImageView。

  public SimpleCursorTreeAdapter (Context context, Cursor cursor, int groupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)

                       cursor       資料庫遊标

                  groupLayout  顯示組元素的資源檔案。該資源檔案定義了如何顯示組元素。該布局檔案必須至少包括groupTo中所定義的View。(即groupTo中的View id數組必須都在該布局檔案中找到)

                       groupFrom       列名清單,顯示ExpandableListView的組節點。

childTo               展示參數“childFrom ”中的列,也就是說ExpandableListView中的視圖顯示的是參數 “childFrom ”的列值,它們應該都是TextView或是ImageView。

五、公共方法

  public SimpleCursorAdapter.ViewBinder getViewBinder ()

  傳回值

                   如果ViewBinder不存在,則傳回null。

  參考

  public void setViewBinder (SimpleCursorTreeAdapter.ViewBinder viewBinder)

.         設定視圖綁定器。

            參數

                 viewBinder 視圖綁定器。可以設定為null來删除已經存在的綁定器。

               參考

  public void setViewText (TextView v, String text)

          僅當ViewBinder不存在或是當ViewBinder不為TextView綁定時(也就是setViewValue()傳回false),則這個方法會被bindView()調用,以便為TextView設定文本。可重寫擴充卡從資料庫中檢索過濾字元串。

             參數

                   v          文本控件引用

                   value      為文本控件設定的文本資訊(譯者注:是從Cursor擷取到的)。

六、受保護方法

  protected void bindChildView (View view, Context context, Cursor cursor, boolean isExpanded)

           通過參數cursor将資料綁定到已有的子視圖上。。

                   參數

                            view                已有視圖,傳回之前調用newChildView建立的視圖。

                            context          應用程式上下文

                            cursor            用于擷取資料的Coursor。Coursor已經移到正确的位置。

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

  protected void bindGroupView (View view, Context context, Cursor cursor, boolean isExpanded)

           通過參數cursor将資料綁定到已有組視圖上。

                   參數                           

                            view                已有組視圖,傳回之前調用newGroupView建立的視圖。

                            isExpanded  組視圖是否呈展開狀态

  protected void setViewImage (ImageView v, String value)

  這個方法會被bindView()調用,以便為ImageView設定圖檔。預設情況下,參數value作為圖檔資源ID來看待,否則會視為圖檔的Uri。   另外還可以通過過濾器來獲得更靈活的設定。

                            v          圖檔控件引用

                            value 圖檔資源ID,是從Cursor擷取到的。

七、補充 

    文章精選

    示例代碼

SimpleCursorTreeAdapter.ViewBinder

譯者署名: 深夜未眠

翻譯時間:2011-3-3

版本:Android 3.0 r1

結構

繼承關系

public static interface SimpleCusrorTreeAdapter.ViewBinder

android.widget.SimpleCursorTreeAdapter.ViewBinder

類概述

這個内部接口可以在外部通過SimpleCursorTreeAdapter.ViewBinder的方式進行 Cursor與View的綁定。Android推薦我們采用這種方式進行綁定操作,而不是沿用SimpleCursorTreeAdapter内部的方式。

參見

公共方法

public abstract boolean setViewValue (View view, Cursor cursor, int columnIndex)

  将指定的列資料綁定到指定的視圖上。當ViewBinder處理綁定時,這個方法必須傳回true;否則SimpleAdapter将嘗試通過其内部預設的方法綁定資料。

                            view                         被綁定的視圖。

                            cursor                      資料庫遊标,綁定資料從它這裡擷取

                            columnIndex          列位置,能夠在資料庫遊标中尋找到。

                   傳回值

                                傳回true意味着資料與視圖已經綁定上,否則為未綁定上。