zoukankan      html  css  js  c++  java
  • 三级扩展列表 学习心得

    @Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        final ExpandableListView expandableListView = getExpandableListView();
        /**
         * 这里每个exListView 只有一个元素, 每个元素代表二级目录的每个目录 
         * 
         */
        EntryChild child = getChild(groupPosition, childPosition);
        ArrayList<EntryChild> arrayList = new ArrayList<EntryChild>();
        arrayList.add(child);
        
        System.out.println("--- > getChildView " + groupPosition +"."+ childPosition + child);
        ChildAdapter childAdapter = new ChildAdapter(context, arrayList);
        expandableListView.setAdapter(childAdapter);
    
        
        expandableListView.setOnChildClickListener(new OnChildClickListener() {
    
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                System.out.println("click: " + groupPosition + ", " + childPosition);
                return false;
            }
        });
        /**
         * 子ExpandableListView展开时,因为group只有一项,所以子ExpandableListView的总高度=
         * (子ExpandableListView的child数量 + 1 )* 每一项的高度
         */
        expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {
    
            @Override
            public void onGroupExpand(int groupPosition) {
                AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
                        50 * (getChild(groupPosition, childPosition).data.size()+1));
                expandableListView.setLayoutParams(lp);
            }
        });
    
        /**
         * 子ExpandableListView关闭时,此时只剩下group这一项,
         * 所以子ExpandableListView的总高度即为一项的高度
         * */
        
        expandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
            
            @Override
            public void onGroupCollapse(int groupPosition) {
                LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 50);
                expandableListView.setLayoutParams(lp);
                
            }
        });
    
        return expandableListView;
    }
    
    private ExpandableListView getExpandableListView() {
        ExpandableListView expandableListView = new ExpandableListView(context);
        LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 50);
        expandableListView.setLayoutParams(lp);
        return expandableListView;
    }
  • 相关阅读:
    -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
    map合并,相同键对应的值相加
    oracle截取字符串去掉字段末尾指定长度的字符
    springMVC结合AjaxForm上传文件
    hibernate中指定非外键进行关联
    Maven安装及MyEclipse中使用Maven
    js判断字符串出现的次数
    PL/SQL如何调试sql语句、存储过程
    如何让pl/sql developer记住密码,实现快速登录
    【学亮IT手记】jQuery each()函数用法实例
  • 原文地址:https://www.cnblogs.com/toolbear/p/6095236.html
Copyright © 2011-2022 走看看