二级列表ExpandableListView的运用

本文介绍了如何在Android中使用二级列表ExpandableListView。通过设置数据源、创建适配器、定义子布局,以及绑定数据,展示了实现二级列表的基本步骤。特别强调了ExpandableListView不同于普通ListView的适配器,并提供了监听子项点击的示例。
摘要由CSDN通过智能技术生成

二级列表的运用,写代码是偶然用到了二级列表,在这里记录一下自己的心得,便于以后复习,对于二级列表,其实感觉跟其他的ListView,GridView等放数据的控件没有太大的区别,具体的步骤都是:
设置数据源->创建适配器->创建子布局用来展示数据->绑定适配器 最后显示数据
自己感觉学会一类对于其他的都好理解,可能就是触类旁通吧!
对于二级列表,他有专门的适配器,在这里就不能使用BaseAdapter这种常规的适配器了 稍后讲到,先看看效果图
没展开的
打开的
对于布局文件的代码,就是一个ExpandableListView控件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity"
    android:orientation="vertical">
    <ExpandableListView
        android:id="@+id/ExlistView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ExpandableListView>
</LinearLayout>

因为我们用到的是二级列表,所以要定义两个子布局,用来分别存放父列表的内容和字列表的内容

用于存放父列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/Gr"
        android:layout_width="match_parent"
        android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值