ExpandableListView使用,点击条目请求网络数据,箭头在右边
来源:互联网 发布:为什么要营改增 知乎 编辑:程序博客网 时间:2024/06/03 07:09
先说下我这面的需求:
项目中用到了ExpandableListView,原本是两种方案,
一.两级数组同时填充(我开始这样做的,后来因为数据量太大就改了)
二.进入页面返回组数据,然后点击组的条目时候在请求里面的子数据
下面直接就上代码和编写的过程了(按照方案二来做的)。
上效果图
1.首先是获取
组上的时间数据,这里访问一个接口,返回一组数据,然后进行一次赋值,添加到集合里面
private List<String> gruops = new ArrayList<String>();2.完成后要对组下面的子集和进行初始化(这个必须要有,不然会奔溃额),然后填充数据。
//初始化数据for (int i = 0; i < gruops.size(); i++) {childs.add(new LinkedList<MatchEntity>());}3.我这里是在点击组条目时候去请求网络查询子条目的数据,并添加到子条目的集合中。
private List<LinkedList<MatchEntity>> childs = new ArrayList<LinkedList<MatchEntity>>();下面这比较关键了,在添加的时候要在对应的位置上添加
List<MatchEntity> match = result.getData().getMatch();childs_1 = new LinkedList<MatchEntity>();childs_1.addAll(match);childs.set(i, childs_1);initDateGruop();//这是填充数据elv_football_single.expandGroup(i, false);//这里是控制展开和收起的作用一会说4.下面是开始要监控点击事件了,这里我是做了一点其他处理,就是如果集合里有数据的情况下是不去请求网络的。
elv_football_single.setOnGroupClickListener(new OnGroupClickListener() {@Overridepublic boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) {boolean expanded = parent.isGroupExpanded(groupPosition);System.out.println("--------"+expanded);if (!expanded) {// 在这加载数据,推荐使用AsycnTask之类的在另一个线程里做喽if (childs.get(groupPosition).size()>0) {initDateGruop();return false;}else{sendHttpLotteryHistory(resultDate.getData().get(groupPosition).getMatchDate(), wLotteryId, groupPosition);return true;}}return false;}});这里主要是根据数据时候为空来配合展示开合状态,源码里面内容比较多,主要是一个回调的机制,这里不做解释了(因为有点多,还没弄的很通顺),基本上是可以实现这种效果了。
补充一个更新集合的代码
if (footballAdapter == null) {footballAdapter = new FootballAdapter(this, gruops, childs);elv_football_single.setAdapter(footballAdapter);} else {footballAdapter.notifyDataSetChanged();}补充去除系统自带的上下箭头,在xml中写:
android:groupIndicator="@null"右面的那个按钮我是直接加在了组条目的布局文件中,做了一个选择器,这里就不多说了。
以上基本就是流程了,过程中还是会有比较多的问题,奔溃的很多次才完善的。如有问题欢迎指教
0 0
- ExpandableListView使用,点击条目请求网络数据,箭头在右边
- 请求网络数据后点击子条目Intent传值(简易)
- 设置ExpandableListView右边的箭头
- 设置ExpandableListView右边的箭头
- 设置ExpandableListView右边的箭头
- 设置ExpandableListView右边的箭头
- 设置ExpandableListView右边的箭头
- ExpandableListView箭头右边显示方法
- ExpandableListView替换右边箭头的实现
- 巧设置ExpandableListView右边的箭头
- 【Tech-Android-View】巧设置ExpandableListView右边的箭头
- 替换ExpandableListView右边箭头Group Indicator(小图标)
- MVP框架+RXJava+reftorfit请求网络数据+XRecycleView多条目展示(banner轮播+条目展示、刷新加载)、点击事件+fresco图片加载
- ExpandableListView 实现点击某个group的时候再去请求网络动态加载子视图中的数据
- Android ExpandableListView点击改变箭头方向
- SSS___listview多条目加载、使用okhttp请求网络数据,Glide加载图片
- ListView多条目展示 请求网络数据 和图片
- 封装请求网络数据 显示XListView 加多条目展示
- POJ 2349 Arctic Network (最小生成树)
- 程序员的感悟之《科技改变了生活,但是缺了点儿什么》
- aerospike 使用总结
- js中的parseInt()函数
- CodeForces 611CNew Year and Domino
- ExpandableListView使用,点击条目请求网络数据,箭头在右边
- ToStringBuilder学习(一):常用方法介绍
- Android的数据库(SQLite)学习
- UICollectionView学习
- 一组感动无数人的职场漫画
- Spring AOP
- 软件质量
- iOS :undefined symbols for architecture x86_64
- ARC 与 MRC 混编