zoukankan      html  css  js  c++  java
  • ExpandableListView方法详解

    正文

      一、结构public interface ExpandableListAdapter 

    间接子类:BaseExpandableListAdapter,CursorTreeAdapter,ResourceCursorTreeAdapter, SimpleCursorTreeAdapter, SimpleExpandableListAdapte

      二、概述

        这个适配器在ExpandableListView和底层数据之间起到了一个衔接的作用。该接口的实现类提供了访问子元素(以组的形式将它们分类)的数据;同样,也提供了为子元素和组创建相应的视图。

      

      三、公共方法

        public abstract boolean areAllItemsEnabled ()

        ExpandableListAdapter里面的所有条目都可用吗?如果是yes,就意味着所有条目可以选择和点击了。返回值:返回True表示所有条目均可用。

        public abstract Cursor getChild (int groupPosition, int childPosition)

        获取指定组中的指定子元素数据。    返回值      返回指定子元素数据。

      public abstract long getChildId (int groupPosition, int childPosition)

      获取指定组中的指定子元素ID,这个ID在组里一定是唯一的。联合ID(getCombinedChildId(long, long))在所有条目(所有组和所有元素)中也是唯一的。

    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()包含了头部和尾部,适配器可能需要不同的行为。

           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  取消这个观察者的注册

    四、补充 ExpandableListView.OnChildClickListener

    结构

    继承关系

    public static interface ExpandableListView.OnChildClickListener

    类概述

    这是一个定义了当可折叠列表(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

    结构

    继承关系

    public static interface 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

    结构

    继承关系

    public interface ExpandableListView.OnGroupCollapseListener 

    类概述

             当收缩某个组时,就会发出通知。

    公共方法

           public abstract void onGroupCollapse (int groupPosition)

             每当收缩当前可伸缩列表中的某个组时,就调用该方法。

                       参数

                                groupPosition 组位置,也就是收缩的那个组的位置。

      

    ExpandableListView.OnGroupExpandListener

    结构

    继承关系

    public interface ExpandableListView.OnGroupExpandListener 

    类概述

             当展开某个组时,就会发出通知。

    公共方法

      public abstract void onGroupExpand (int groupPosition)

      每当展开当前可伸缩列表中的某个组时,就调用该方法。

        参数

                                groupPosition 组位置,也就是展开的那个组的位置。

    http://blog.sina.com.cn/s/blog_b37dcd9701017s61.html

  • 相关阅读:
    sso单点登录
    mysql java写入时间少14小时
    mysql 时间
    mysql中timestamp的自动生成与更新
    centos7下用命令安装node&pm2
    腾讯蓝鲸资源分配
    Centos7 安装谷歌浏览器
    Ubuntu安装Apache 2.4.7常见问题解答
    Ubuntu常见服务启停
    LVM 'Can’t open /dev/sdb1 exclusively. Mounted filesystem?' Problem
  • 原文地址:https://www.cnblogs.com/cmblogs/p/4729954.html
Copyright © 2011-2022 走看看