先看下效果图:

第一个是展开的效果,剩下两个是关闭的效果。

包含三个文件,一个 java,另一个重写的BaseExpandableListAdapter,还有一个布局文件

java代码:

public class MainActivity extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        ExpandableListView s = ((ExpandableListView) findViewById(R.id.expandableListView1));
        eda adapter = new eda(this);
        s.setAdapter(adapter);
 
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

adaptert代码:

public class eda extends BaseExpandableListAdapter {
    private Context cxt;
    int[] logos = new int[] { R.drawable.z1, R.drawable.z2, R.drawable.z4 };
    String[] gt = new String[] { "组1", "组2", "组3" };
    String[][] arms = new String[][] { { "狂战士", "雨雪卖身", "asdas" },
            { "高于掐", "神奇的猴子", "不神奇啊" }, { "天才的啥", "士大夫", "q32" } };
 
    public eda(Context ctx) {
        // TODO Auto-generated constructor stub
        this.cxt = ctx;
    }
 
    public Object getChild(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return arms[groupPosition][childPosition];
    }
 
    public long getChildId(int arg0, int childPosition) {
        // TODO Auto-generated method stub
        return childPosition;
    }
 
    public View getChildView(int groupPosition, int childPosition,
            boolean isExpanded, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        TextView t = new TextView(cxt);
        t.setPadding(50, 0, 0, 0);
        t.setText(getChild(groupPosition, childPosition).toString());
        return t;
 
    }
 
    public int getChildrenCount(int groupPosition) {
        // TODO Auto-generated method stub
        return arms[groupPosition].length;
    }
 
    public Object getGroup(int groupPosition) {
        // TODO Auto-generated method stub
        return gt[groupPosition];
    }
 
    public int getGroupCount() {
        // TODO Auto-generated method stub
        return gt.length;
    }
 
    public long getGroupId(int groupPosition) {
        // TODO Auto-generated method stub
        return groupPosition;
    }
 
    public View getGroupView(int groupPosition, boolean isExpanded,
            View converView, ViewGroup parent) {
        // TODO Auto-generated method stub
 
        LinearLayout ll = new LinearLayout(cxt);
        ll.setOrientation(0);
        ImageView logo = new ImageView(cxt);
        logo.setImageResource(logos[groupPosition]);
        ll.addView(logo);
        TextView tt = new TextView(cxt);
        tt.setText(getGroup(groupPosition).toString());
        ll.addView(tt);
        return ll;
    }
 
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return true;
    }
 
    public boolean isChildSelectable(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return false;
    }
 
}

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
 
 
 
    <ExpandableListView
        android:id="@+id/expandableListView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:childIndicator="@drawable/z3" >
 
    </ExpandableListView>
 
</LinearLayout>

转载于:https://www.cnblogs.com/Mr-Joe/archive/2012/11/15/2771910.html

折叠list ExpandableList+ BaseExpandableListAdapter 自定义 折叠列表相关推荐

  1. 【Flutter】自定义折叠组件

    一.基础组件 import 'package:flutter/material.dart';const Duration _kExpand = Duration(milliseconds: 200); ...

  2. 疯狂的折叠屏!不买折叠手机的5个理由

    这几天,手机界掀起了新概念:折叠屏. "折叠"概念兴起后,一方面各厂商受到媒体追捧,一方面受到业内人士"疯狂"吐槽,虽然尚未有任何一款折叠机上市,但" ...

  3. Manjaro-KDE自定义应用列表

    目录 Manjaro-KDE自定义应用列表 1.不是AUR安装到新软件-Isabelle为例 2.已有的执行文件脚本类想放在程序目录 Manjaro-KDE自定义应用列表 使用 Maanjaro-KD ...

  4. 【HTML | 模板】自定义 商品列表 (商品表格)

    预览图 项目结构 下载BootStrap 样式:bootstrap.min.css ============================= HTML <html><head> ...

  5. 动态渲染element组件el-table表头项+自定义el-table列表项

    动态渲染el-table表头项+自定义el-table列表项 现在不少项目的表格需要结合穿梭框动态显示表头有哪些项,但按照el-table原本的设置,有多少项就直接在html写多少个el-table- ...

  6. el-upload自定义文件列表

    <el-upload:action="uploadUrl"ref="importUpload":auto-upload="false" ...

  7. 使用Java语言while循环来实现假如我有一张足够大的纸,他的厚度为0.1毫米 请问折叠多少次,可以折叠到珠峰高度?

    使用Java语言while循环来实现假如我有一张足够大的纸,他的厚度为0.1毫米 请问折叠多少次,可以折叠到珠峰高度? /* while 循环 需求: 世界上最高的山峰是珠穆朗玛峰(8844.43米= ...

  8. android折叠布局,Android中FoldingLayout折叠布局的用法及实战全攻略

    一.概述无意中翻到的FoldingLayout的介绍的博客,以及github地址.感觉很nice呀,于是花了点时间研究以及编写,本篇博客将带大家从最基本的原理分析,一步一步的实现我们的FoldingL ...

  9. win7计算机文件夹折叠,win7系统折叠组窗口设置不折叠的操作方法

    很多小伙伴都遇到过对win7系统折叠组窗口设置不折叠进行设置的困惑吧,一些朋友看过网上对win7系统折叠组窗口设置不折叠设置的零散处理方法,并没有完完全全明白win7系统折叠组窗口设置不折叠是如何设置 ...

最新文章

  1. 阿里云安全肖力:安全基础建设是企业数字化转型的基石
  2. hdu 1495 非常可乐 (bfs)
  3. U盘启动盘制作方法 2种绝招轻松搞定
  4. xcode 选择configuraftions 打包_分利宝IOS自动化打包
  5. jq监听子元素被点击_vue开发app点击字母展示地区列表(兄弟组件之间联动)
  6. Python中[:]与[::]的用法
  7. Google传奇Jeff Dean最新演讲:如何构建未来的机器学习芯片
  8. ios batchRequest
  9. 计算机算法设计与分析 N后问题
  10. python 通用数据库类型_Python开发基础之Python常用的数据类型
  11. 管理感悟:承认错误,善于总结
  12. 计算机博弈的代码java,Java 速成
  13. 8光12电ERPS工业级环网交换机 PLC自动化环网柜一键环网交换机
  14. 谈谈滞后补偿器与PI控制及其原理分析
  15. python3.6 scrapy模块查询POS后台获取指定时间和状态的订单存入到excel表格中
  16. 基于mysql的报表工具有哪些?值得推荐的mysql报表工具
  17. 讲师征集令 | Apache DolphinScheduler Meetup分享嘉宾,期待你的议题和声音!
  18. 使用python监控NTP系统(时钟服务器)
  19. 机器学习实战- 回归(Regression) 概述
  20. linux ctrl r 搜索,linux下用ctrl+r快速搜索history命令

热门文章

  1. EVE-NG之Cisco FirePower 系统
  2. Java_spring_定时执行任务
  3. Delphi 延迟函数 比sleep 要好的多
  4. Response.Write 用法总结
  5. OC代码调用C++代码的回调函数步骤
  6. vlc学习计划(2)---二进制包安装及使用
  7. Flash 与数学:圆的切线(2)
  8. Olympic Games -basketball
  9. 《C++ Primer》读书笔记
  10. Linux也使用多线程下载