public class ExpandableListViewActivity extends Activity {
//声明对象
private SimpleExpandableListAdapter adapter=null;
List<Map<String,String>> groups;
List<List<Map<String,String>>> childs;
ExpandableListView expandableListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandable_list_view);
//为ExpandableListView 准备数据
groups=new ArrayList<Map<String,String>>();
Map<String,String> group1= new HashMap<String, String>();
group1.put("group", "我的家人");
Map<String,String> group2=new HashMap<String,String>();
group2.put("group", "我的朋友");
groups.add(group1);
groups.add(group2);
childs =new ArrayList<List<Map<String,String>>>();
List<Map<String,String>> child1=new ArrayList<Map<String,String>>();
Map<String,String> child1Data1=new HashMap<String, String>();
child1Data1.put("child", "妈妈");
child1.add(child1Data1);
Map<String,String> child1Data2=new HashMap<String, String>();
child1Data2.put("child", "爸爸");
child1.add(child1Data2);
List<Map<String,String>> child2=new ArrayList<Map<String,String>>();
Map<String,String> child1Data3=new HashMap<String, String>();
child1Data3.put("child", "小飞");
child2.add(child1Data3);
Map<String,String> childData4=new HashMap<String, String>();
childData4.put("child", "小武");
child2.add(childData4);
childs.add(child1);
childs.add(child2);
//得到ExpandableListView对象
expandableListView =(ExpandableListView)findViewById(R.id.expandable_1);
//实例化适配器
adapter=new SimpleExpandableListAdapter(this,groups,R.layout.tree_group,
new String[]{"group"},new int[]{R.id.tree_group_textView},
childs,R.layout.tree_child,new String[]{"child"},new int[]{R.id.textView1}
);
//设置适配器
expandableListView.setAdapter(adapter);
//设置监听器
expandableListView.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.d("text","group"+groupPosition);
Log.d("text", "child"+childPosition);
return false;
}});
}
}
分享到:
相关推荐
本源码将演示Android ExpandableListView的用法,制作一个类似QQ界面的好友分组列表展开收缩效果,为什么最开始没有使用ListView呢?因为ListView只能显示一级列表,如果实现像QQ好友列表那样的效果,就需要用到...
两种实现城市列表的方法,ExpandableListView推荐使用这种方法。
本实例简单介绍了android ExpandableListView的使用方法,可以在本例代码基础上稍作修改直接用上项目,或者经简单扩展实现更为复杂的多级列表显示。
记录了Android开发的学习历程,本demo为可拓展的列表控件ExpandableListView的使用方法,并含有要点整理文档。
主要介绍了Android中ExpandableListView的用法,以实例形式展示了Android中的下拉list控件的用法,需要的朋友可以参考下
主要介绍了Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法的相关资料,需要的朋友可以参考下
Android 中使用ExpandableListView 实现分组 一个视图显示垂直滚动两级列表中的条目。这不同于列表视图,允许两个层次,类似于QQ的好友分组。要实现这个效果的整体思路为: 1.要给ExpandableListView 设置适配器,...
模仿QQ好友列表的ExpandableListView实现的效果 现在已实现一个封装好的类出来,只需要把此控件放到RelativeLayout容器中,然后在其Adapter的自定义对象中实现一个HideGroup方法。就可以在Activity里不使用代码实现...
关于ExpandableListView长按事件处理,网上很多都是使用将上下文菜单注册到ExpandableListView上实现长按事件。这样做弊端显而易见,不够灵活,不能分别对父项、子项、父项之间、子项之间弹出内容做区分。下面来说我...
一个树形控件的简单例子,学习使用!很实用哦
安卓ExpandableListView嵌套Gridview嵌套用法,与多点触控图片缩放。代码写的交简单。数据少,但有代表性。
ExpandableListView二级列表非常详细的使用方法以及方便的调用,详解,对代码进行了封装,调用方便,适用于很多场景。
主要为大家详细介绍了Android UI控件ExpandableListView基本用法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
ExpandableListView的group和child都带CheckBox,并点击group或child时再EditView添加对应Button,child全选时显示group的button,否则显示选中Child的Button
GroupList 封装并演示了如何使用Android的ExpandableListView控件,相关博文:Android开发实践:多级列表的封装与应用 PopDialog 封装并演示了如何使用Android的PopupWindow控件,相关博文:Android开发实践:用...
ExpandableListView的基本用法。详见博客:http://www.cnblogs.com/smyhvae/p/5848117.html
ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list); EListAdapter adapter = new EListAdapter(getApplicationContext(), list); //list 是数据源 vList.setAdapter(adapter); //...