三级扩展列表 学习心得

Posted 望远天涯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三级扩展列表 学习心得相关的知识,希望对你有一定的参考价值。

@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;
}

 

以上是关于三级扩展列表 学习心得的主要内容,如果未能解决你的问题,请参考以下文章

Javalucene4.0学习心得

可扩展列表视图在 android 的片段活动中不起作用

如何将可扩展列表视图的选定子视图数据从片段发送到父活动?

Android 嵌套片段方法

在片段中使用列表视图

Python学习心得 : 更新列表