ListView的item折叠功能实现,使用ExpandableListView
来源:互联网 发布:bootcamp for mac 编辑:程序博客网 时间:2024/06/06 08:42
来酷狗面试的时候面试官问过我,如果要显示/隐藏ListView的某个Item项目中的某些内容,我会怎么做。
我当时的回答是,做一个布局文件里面把所有要用到的项目都写上,哪个不需要了就将他设为gone就可以了。
今天在看代码的时候发现,原来有ExpandableListView这个东西,很明显,我当时的回答有点太浅层次了。
ExpandableListView见名知意,专门用于实现可收缩的ListView,即其中的item有父子item。实现的效果大致如下,使用ExpandableListView来做父子Item实现起来相当容易。
ExpandableListView使用ExpandableListAdapter来做为其适配器,ExpandableListAdapter也有其基础适配器BaseExpandableListAdapter;
具体代码如下:
package com.wallj.listviewdemo;import android.R.color;import android.os.Bundle;import android.app.Activity;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.TextView;public class ExpandableListViewDemo extends Activity {ExpandableListView mExpdListView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_expandable_list_view_demo);mExpdListView = (ExpandableListView) findViewById(R.id.exListView);mExpdListView.setAdapter(mExAdapter);}ExpandableListAdapter mExAdapter = new BaseExpandableListAdapter() {private String[] generalsTypes = new String[] { "魏", "蜀", "吴" };private String[][] generals = new String[][] { { "夏侯惇", "甄姬", "许褚", "郭嘉", "司马懿", "杨修" }, { "马超", "张飞", "刘备", "诸葛亮", "黄月英", "赵云" }, { "吕蒙", "陆逊", "孙权", "周瑜", "孙尚香" } };@Overridepublic boolean isChildSelectable(int arg0, int arg1) {return false;}@Overridepublic boolean hasStableIds() {return true;}@Overridepublic View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {if(arg2 == null){arg2 = new TextView(ExpandableListViewDemo.this);((TextView)arg2).setTextSize(30);}((TextView)arg2).setText(generalsTypes[arg0]);return arg2;}@Overridepublic long getGroupId(int arg0) {return arg0;}@Overridepublic int getGroupCount() {return generalsTypes.length;}@Overridepublic Object getGroup(int arg0) {return generalsTypes[arg0];}@Overridepublic int getChildrenCount(int arg0) {return generals[arg0].length;}@Overridepublic View getChildView(int arg0, int arg1, boolean arg2, View arg3,ViewGroup arg4) {if(arg3 == null){arg3 = new TextView(ExpandableListViewDemo.this);}((TextView)arg3).setText(generals[arg0][arg1]);return arg3;}@Overridepublic long getChildId(int arg0, int arg1) {return arg1;}@Overridepublic Object getChild(int arg0, int arg1) {return generals[arg0][arg1];}};}
0 0
- ListView的item折叠功能实现,使用ExpandableListView
- Android使用ExpandableListView实现折叠的效果
- ExpandableListView,可展开和折叠的ListView
- ExpandableListView中ListView无法使用Item的监听事件
- 实现listview的item侧滑功能
- listview的使用-ExpandableListView
- Android常用控件(能折叠的ListView)--ExpandableListView的使用模仿QQ好友列表
- listview和Expandablelistview实现购物车功能
- 使用ExpandableListView实现ListView嵌套ListView
- 关于listview的item实现滑动删除功能实现
- android实现ListView或GridView中item的倒数功能
- 实现类似listView中动态添加Item的功能
- ExpandableListView实现商品列表折叠
- gedit折叠功能的实现
- 使用ExpandableListView实现树状ListView两级分层
- ExpandableListView的使用,可展开的ListView
- 09 ListView监听 ExpandableListView的使用总结
- listview的item中单多选实现
- eclipse中导入myeclipse的web项目
- 很多网站 需要身份证号码 注册 轻松通过
- android安卓Jni编译提示fatal error: vector: No such file or directory
- LeetCode:String to Integer (atoi) -one solution coded by c language
- 并查集
- ListView的item折叠功能实现,使用ExpandableListView
- iOS开发中遇到的i386
- android webservices使用教程及遇到问题总结
- 学习笔记(objective-c)-重写description方法
- HDU2102---A计划(附测试数据)
- TCP/IP协议族-----2、OSI模型和TCP/IP协议族
- MyBatis动态SQL
- 【UFLDL】稀疏自编码器AE
- 理解java程序调用机制