Java转身系列之安卓5:ExpandableListView制作视频播放列表——LayoutInflater布局管理、Adapter适配模式、Android MVC

Java转身系列之安卓5:ExpandableListView制作视频播放列表

在系列文章第3篇,根据设定的MyPlayer播放器业务需求,需要实现对视频简单分类,并且设计了一个主界面原型:

main activity prototype

在安卓UI组件当中,ExpandableListView可以实现折叠式分类列表,在这一篇中利用该组件进行主界面实现。

新建MainActivity,layout设置为LinearLayout,orientation方向设置为vertical垂直方向:

main activivity xml

从界面拖拽或者在xml中增加ExpandableListView组件,layout_width和layout_height都设置为match_parent,表示占据完父容器的宽和高。

expand list design

设计器中,ExpandableListView的呈现与layout布局无差别。该组件的api说明摘要:

expandable list view api

ExpandableListView有一个父类是视图组ViewGroup,这个组件是所有layout布局类的父类,也就是说ExandableListView也是一个组件布局容器。

该视图将两级列表项以垂直滚动方式显示,它与ListView的差别是允许两级:组可以被单独展开显示它的子项。列表项来自于与该视图绑定的ExpandableListAdapter。

要让ExpandableListView显示数据,需要了解和使用ExpandableListAdapter这个接口。

An adapter that links a ExpandableListView with the underlying data. The implementation of this interface will provide access to the data of the children (categorized by groups), and also instantiate Views for children and groups.

适配器将ExpandableListView与底下的数据连结。接口实现将提供以组分类的子项数据访问,并为视图充实子项与分组数据。

在给ExpandableListView填充数据前,先对录像进行数据建模。

根据需求分析,录像可以分类,有名称和播放url地址。新增两个类,VideoCategory与Video,呈一对多关系:

public class VideoCategory {
   
    private String name;
    private List<Video> videos;//录像列表
    public String getName() {
  return name;}
    public void setName(String name) {
  this.name = name;}
    public List<Video> getVideos() {
  return videos;}
    public void setVideos(List<Video> videos) {
  this.videos = videos;}
}
public class Video {
   
    private String name;
    private String url;//播放地址
    public String 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值