android-ExpandableList可展开的list

article/2025/11/4 8:27:04

ExpandableList可展开的list

老规矩。右键取得显示不出来的图片地址,利用下载工具下载这个图片。后缀改为rar即可得到源代码项目。


package zhang.EspandableListView;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter;public class Espandable extends ExpandableListActivity {	/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// 定义一个list。该list对象为一级条目提供数据List<Map<String,String>> groups = new ArrayList<Map<String,String>>();Map<String,String> group1= new HashMap<String,String>();group1.put("group", "group1");groups.add(group1);Map<String,String> group2= new HashMap<String,String>();group2.put("group", "group2");groups.add(group2);//定义一个list 该list·对象为第一个一级条目提供二级条目的数据List<Map<String,String>> child1=new ArrayList<Map<String,String>>();Map<String,String> childDate11= new HashMap<String,String>();childDate11.put("child", "childDate11");child1.add(childDate11);Map<String,String> childDate12= new HashMap<String,String>();childDate12.put("child", "childDate12");child1.add(childDate12);//定义一个list 该list·对象为第二个一级条目提供二级条目的数据List<Map<String,String>> child2 =new ArrayList<Map<String,String>>();Map<String,String> childDate21 =new HashMap<String,String>();childDate21.put("child", "childDare21");child2.add(childDate21);Map<String,String> childDate22= new HashMap<String,String>();childDate22.put("child", "childDate22");child2.add(childDate22);// 定义一个list该list对象用来存储所有的二级条目的数据List<List<Map<String,String>>> childs = new ArrayList<List<Map<String,String>>>();childs.add(child1);childs.add(child2);//1生成一个simpleExpandableListAdapter//2context//3 一级条目的样式布局文件//4·指定一级条目数据的key//5指定一句条目数据显示控件的ID//6指定二级条目的数据//7指定二级条目的布局文件//8指定二级条目数据的key//9指定二级条目数据显示控件的IDSimpleExpandableListAdapter sela=  new SimpleExpandableListAdapter(this,groups,R.layout.gruop,new String[]{"group"},new int[]{R.id.gruopTo},childs,R.layout.child,new String[]{"child"},new int []{R.id.childTo});setListAdapter(sela);}
}

主页布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ExpandableListView android:id="@id/android:list" android:layout_height="fill_parent" android:layout_width="fill_parent"android:drawSelectorOnTop="false"></ExpandableListView>
<TextView  android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Date"/>
</LinearLayout>

一级list的布局  gruop。xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView  android:id="@+id/gruopTo"android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Data"android:paddingLeft="60px"android:paddingTop="10px"android:textSize="26sp"/>
</LinearLayout>

子布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView  android:id="@+id/childTo"android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Data"android:paddingLeft="30px"android:paddingTop="5px"android:textSize="16sp"/>
</LinearLayout>



http://chatgpt.dhexx.cn/article/gw88vOKP.shtml

相关文章

android 二级折叠列表,Android折叠列表 ExpandableList

ExpandableList 是折叠列表,通过继承ExpandableListActivity 类就可以非常简单的实现折叠列表。 效果图: 代码实现 package com.zhou.activity; import android.app.ExpandableListActivity; import android.os.Bundle; import android.view.ContextMenu; import android.vie…

ExpandableListView的使用

ExpandableListView的使用 效果图 布局 <ExpandableListViewandroid:id"id/expandableListView"android:layout_width"match_parent"android:layout_height"match_parent" /> 初始化 ExpandableListView expandableListView (Expanda…

ExpandableListView简介

学习笔记&#xff0c;欢迎指导。 最近做了一个项目&#xff0c;需要一个层级列表&#xff0c;完成之后&#xff0c;就顺便来做个博客简介一下。 △基本简介 →“ExpandableListView”是对“ListView”做的扩展&#xff0c;“ListView”是个列表&#xff0c;而“ExpandableLis…

浅析——ExpandableListView的使用

ExpandableListView&#xff08;可扩展的ListView&#xff09; ExpandableListVivew是ListView的子类&#xff0c;它在普通ListView的基础上进行了扩展&#xff0c;它把应用中的列表项分为几组&#xff0c;每组里又可包含多个列表项。ExpandableListVivew的用法与普通ListView的…

ExpandableListView的应用

使用ExpandableListView实现下拉菜单栏 xml布局 1.activity_main.xml <ExpandableListView xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto"xmlns:tools"http://schemas.android.…

ExpandableListView说明及其用法

一&#xff1a;ExpandableListView ExpandableListView&#xff0c;是可展开的列表组件的ExpandableListView的用法和ListView非常像&#xff0c;只是其所显示的列表项应该由ExpandableListAdapter提供&#xff0c;下面是它的xml属性及说明&#xff1a; childDivider&#xff…

关于ExpandableListView用法的一个简单小例子

喜欢显示好友QQ那样的列表&#xff0c;可以展开&#xff0c;可以收起&#xff0c;在android中&#xff0c;以往用的比较多的是listview&#xff0c;虽然可以实现列表的展示&#xff0c;但在某些情况下&#xff0c;我们还是希望用到可以分组并实现收缩的列表&#xff0c;那就要用…

ExpandableListView扩展(BaseExpandableListAdapter的使用)

针对普通的ExpandableListView的使用&#xff0c;即&#xff0c;需要显示的数据全都是使用TextView显示时&#xff0c;我们使用SimpleExpandableListAdapter就可以了。 但是如果是相对复杂的ExpandableListView&#xff0c;那么SimpleExpandableListAdapter就不满足我们的要求…

ExpandableListView控件的使用

目录 一、ExpandableListView的介绍 二、适配器&#xff08;ExpandableAdapter&#xff09; 1、BaseExpandableListAdapter&#xff1a; BaseExpandableListAdapter例子 一、ExpandableListView的介绍 ExpandableListView是ListView的子类。它是ListView的基础上进行了扩展&…

ExpandableListView的使用详解

在Android开发中&#xff0c;我们知道经常会用到ListView来加载一些列表数据&#xff0c;但有时候ListView并不能完全十分满足我们的需求。比如如下图的效果用 ExpandableListView实现起来就更方便点&#xff0c;我们直接用ExpandableListView&#xff0c;设置Group不能点击即可…

ExpandableListView实例

先来看效果图&#xff1a; demo中有三个group item和多个child item&#xff0c;group item包括一个指示器&#xff0c;一个标题和一个按钮。child item包括一个图片&#xff0c;一个标题和一个按钮。先来实现布局文件 1 activity_main.xml <?xml version"1.0&qu…

ExpandableListView使用方法详解

一、前言 “好记性不如烂笔头”&#xff0c;再次验证了这句话是真的很有道理啊&#xff0c;一个月前看了一下ExpandableListView的使用&#xff0c;今天再看居然忘了这个是干啥的了&#xff0c;今天就详细讲解一下ExpandableListView的使用方法&#xff0c;感觉对于二级条目显示…

ExpandableList的使用

首先&#xff0c;我们把一二级选择的对应的类写好。 看这些代码&#xff0c;最主要的是我在ParentStrings中写了一个List<ChildrenStrings>的一个方法&#xff0c;以便之后ChildrenStrings的存储和调用 下面是BusAdapter继承BaseExpandableAdapter public class BusAda…

可折叠列表ExpandableList

ExpandableList就是可展开的ListView 首先我们来看一下页面的布局 expandlist_layout.xml文件 <RelativeLayoutxmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto"xmlns:tools"htt…

Adapter类控件使用之ExpandableList(可折叠式列表)的基本使用

(一)概述 本节要讲解的Adapter类控件是ExpandableListView,就是可折叠的列表,它是 ListView的子类, 在ListView的基础上它把应用中的列表项分为几组,每组里又可包含多个列表项。至于 样子, 类似于QQ联系人列表,他的用法与ListView非常相似,只是ExpandableListViv…

如果在临汾遇见你

哈 如果在临汾遇见你&#xff0c;那么&#xff0c;我们一定要去平阳南街煤化巷口的宾库西餐厅&#xff0c;坐在只需消费15块钱就可以坐一整天的大厅散座上&#xff0c;聊着我们相见恨晚的话题。 如果在临汾遇见你&#xff0c;那么&#xff0c;我们一定要去传说的尧庙&#xff0…

吃完7家互联网大厂食堂,我回去就把老板开了

本文转载自 超人测评 不会还有人不知道&#xff08;中文&#xff09;字节跳动&#xff08;英文&#xff09;Bytedance的工牌&#xff0c;已经成为年轻人的社交货币了吧。 有人说它是“相亲市场的硬通货”&#xff0c;也有人将它称为“2021年最潮流时尚单品”。每当你在奶茶店…

围剿宏光MINI

NEW 关注Tech逆向思维视频号 最新视频→【做核酸&#xff1f;打疫苗&#xff1f;3分钟假期安全出行攻略】 出品&#xff5c;深途 文&#xff5c;黎明 编辑&#xff5c; 魏佳 有很长一段时间&#xff0c;汽车企业的老板和投资人&#xff0c;都热衷于造“大车”。蔚来、小鹏、威马…

《植物大战僵尸》的12个成功秘诀

口述 / James Gwertzman 整理 / 杨东杰 [caption id"attachment_6675" align"alignleft" width"263" caption"James Gwertzman PopCap亚太区总裁"] [/caption] 4月28日&#xff0c;在由长城会和CSDN联合主办的“开发者星球——TUP大…

只要10分钟,搭建属于个人的炫酷网站,你还在犹豫什么?

&#x1f482; 个人主页: IT学习日记&#x1f91f; 版权: 本文由【IT学习日记】原创、在CSDN首发、需要转载请联系博主&#x1f4ac; 如果文章对你有帮助、欢迎关注、点赞、收藏(一键三连)和订阅专栏哦&#x1f485; 想寻找共同成长的小伙伴&#xff0c;请点击【技术圈子】 文章…