当前位置: 首页 > news >正文

ExpandableListView说明及其用法

一:ExpandableListView
ExpandableListView,是可展开的列表组件的ExpandableListView的用法和ListView非常像,只是其所显示的列表项应该由ExpandableListAdapter提供,下面是它的xml属性及说明:

  1. childDivider:指定各组内子项列表项之间的分割条
  2. childIndicator:显示在子列表项旁边的Drawable对象
  3. groupIndicator:显示在组列表项旁边的Drawable对象

二:效果

在这里插入图片描述
三:使用
第一步:新建包,列表中显示的数据是从网络请求过来,并且插入到数据库中
在这里插入图片描述
1.Android开发中使用Bean类最多的场景是从网络获取数据,将数据以Bean类组织,Bean类中的数据用于填充UI界面中的控件。此处使用Bean类主要是组织数据方便,便于将其中的数据填充到控件中。

2.biz是Business的缩写,实际上就是控制层,控制层的主要作用就是协调model层和view层直接的调用和转换。能够有效的避免请求直接进行数据库内容调用,而忽略了逻辑处理的部分。实际上biz就起到了一个server服务的角色,很好的沟通了上层和下层直接的转换,避免在model层进行业务处理(代码太混乱,不利于维护)

第二步:代码编写

1.Chapter.javapackage com.hanjie.expandablelistview2.bean;import java.util.ArrayList;
import java.util.List;public class Chapter {private int id;private String name;public static final String TABLE_NAME = "tb_chapter";public static final String COL_ID = "_id";public static final String COL_NAME = "name";private List<ChapterItem> children = new ArrayList<>();public Chapter() {}public Chapter(int id, String name) {this.name = name;this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public List<ChapterItem> getChildren() {return children;}public void addChild(ChapterItem child) {children.add(child);child.setPid(getId());}public void addChild(int id, String childName) {ChapterItem chapterItem = new ChapterItem(id, childName);chapterItem.setPid(getId());children.add(chapterItem);}public int getId() {return id;}public void setId(int id) {this.id = id;}}2.ChapterItem.javapackage com.hanjie.expandablelistview2.bean;
​
​
​
public class ChapterItem {private int id;private String name;private int pid;public static final String TABLE_NAME = "tb_chapter_item";public static final String COL_ID = "_id";public static final String COL_PID = "pid";public static final String COL_NAME = "name";public ChapterItem() {}public ChapterItem(int id, String name) {this.name = name;this.id = id;}public int getId() {return id;}public int getPid() {return pid;}public void setPid(int pId) {this.pid = pId;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}3.ChapterLab.javapackage com.hanjie.expandablelistview2.bean;import java.util.ArrayList;
import java.util.List;
​
​
​
public class ChapterLab {public static List<Chapter> generateDatas() {
​List<Chapter> chapters = new ArrayList<>();
​
​Chapter root1 = new Chapter(1, "Android");Chapter root2 = new Chapter(2, "IOS");Chapter root3 = new Chapter(3, "Unity 3D");Chapter root4 = new Chapter(4, "Cocos2d-x");
​root1.addChild(1, "PullToRefresh");root1.addChild(2, "Android 8.0通知栏解决方案");root1.addChild(4, "Android 与WebView的js交互");root1.addChild(8, "Android UiAutomator 2.0 入门实战");root1.addChild(10, "移动端音频视频入门");
​root2.addChild(11, "iOS开发之LeanCloud");root2.addChild(12, "iOS开发之传感器");root2.addChild(13, "iOS开发之网络协议");root2.addChild(14, "iOS之分享集成");root2.addChild(15, "iOS之FTP上传");
​
​root3.addChild(16, "Unity 3D 翻牌游戏开发");root3.addChild(17, "Unity 3D基础之变体Transform");root3.addChild(20, "带你开发类似Pokemon Go的AR游戏");root3.addChild(21, "Unity 3D游戏开发之脚本系统");root3.addChild(22, "Unity 3D地形编辑器");
​
​root4.addChild(25, "Cocos2d-x游戏之七夕女神抓捕计划");root4.addChild(26, "Cocos2d-x游戏开发初体验-C++篇");root4.addChild(27, "Cocos2d-x全民俄罗斯");root4.addChild(28, "Cocos2d-x坦克大战");root4.addChild(30, "新春特辑-Cocos抢红包");
​
​chapters.add(root1);chapters.add(root2);chapters.add(root3);chapters.add(root4);return chapters;}}4.ChapterBiz.javapackage com.hanjie.expandablelistview2.biz;import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
​
​
import com.hanjie.expandablelistview2.bean.Chapter;
import com.hanjie.expandablelistview2.bean.ChapterItem;
import com.hanjie.expandablelistview2.dao.ChapterDao;
import 
http://www.xdnf.cn/news/834661.html

相关文章:

  • 网址收藏
  • 关闭浏览器弹出框onbeforeunload,onunload和onunloadcancel
  • 浅谈“游戏行业第三方支付平台“
  • 学习QT之容器类
  • 电脑无法打开Excel文件怎么办?
  • 如何获得CSDN下载积分和C币规则
  • Java网络编程:概述--快速入门
  • Linux 大文件如何切割与合并?
  • `simple-reactjs-app` 开源项目使用指南
  • python怎么存储数据_【Python】存储数据
  • 【zip密码破解】AZPR==>ARCHPR4.5
  • 机器人学笔记(2)正运动学
  • 打造专业级网页排版:全方位解析专业字体家族font-family实践与全球知名字体库导览
  • 如何使用PartitionMagic 8.0汉化版(图文说明)(转载)
  • debian12.5国内镜像源配置清单
  • 【WinForm】WinForm中的TableLayoutPanel控件、PropertyGrid控件、PictureBox控件、ListView控件、DataGridView控件的使用
  • 嵌入式系统电源管理软件比较
  • 技术干货 | GreatDB新一代读写分离架构,如何炼就近乎0损耗的性能?
  • C# Invoke和BeginInvoke的区别
  • python中shutil.copyfile的用法_python处理文件和文件的方法(shutil,filecmp ,MD5,tarfile,zip)...
  • FTP地址大全
  • GoLang之interface
  • PostgreSQL学习总结(13)—— PostgreSQL 目录结构与配置文件 postgresql.conf 详解
  • 骡友们推荐的各个学习英文网站的汇总
  • 【Unity插件】最多的插件合集
  • CDMA2000简介
  • Scanner类中next()、nextInt()和nextLine()方法的区别
  • Windows Server 2008 各版本介绍
  • Java——防止SQL注入的几种策略
  • 网络安全方面有哪些认证,看完这篇你就知道了