转载自http://blog.csdn.net/xiangyong2008/archive/2010/03/06/5351969.aspx

ExpandableListActivity:

An activity that displays an expandable list of items by binding to a data source implementing the ExpandableListAdapter, and exposes event handlers when the user selects an item.

即,可扩展的list,单击某个item后,又可显示一个子list。它的数据通过绑定到ExpandableListAdapter或者ExpandableListAdapter的子类上。

示例1—通过SimpelExpandableListAdapter绑定数据:

view plain copy to clipboard print ?
  1. publicclassExpandableList3extendsExpandableListActivity{
  2. privatestaticfinalStringNAME="NAME";
  3. privatestaticfinalStringIS_EVEN="IS_EVEN";
  4. privateExpandableListAdaptermAdapter;
  5. @Override
  6. publicvoidonCreate(BundlesavedInstanceState){
  7. super.onCreate(savedInstanceState);
  8. List<Map<String,String>>groupData=newArrayList<Map<String,String>>();
  9. List<List<Map<String,String>>>childData=newArrayList<List<Map<String,String>>>();
  10. for(inti=0;i<20;i++){
  11. Map<String,String>curGroupMap=newHashMap<String,String>();
  12. groupData.add(curGroupMap);
  13. curGroupMap.put(NAME,"Group"+i);
  14. curGroupMap.put(IS_EVEN,(i%2==0)?"Thisgroupiseven":"Thisgroupisodd");
  15. List<Map<String,String>>children=newArrayList<Map<String,String>>();
  16. for(intj=0;j<15;j++){
  17. Map<String,String>curChildMap=newHashMap<String,String>();
  18. children.add(curChildMap);
  19. curChildMap.put(NAME,"Child"+j);
  20. curChildMap.put(IS_EVEN,(j%2==0)?"Thischildiseven":"Thischildisodd");
  21. }
  22. childData.add(children);
  23. }
  24. //Setupouradapter
  25. mAdapter=newSimpleExpandableListAdapter(
  26. this,
  27. groupData,//存储父list的数据
  28. android.R.layout.simple_expandable_list_item_2,//父list的现实方式
  29. newString[]{NAME,IS_EVEN},//父list需要显示的数据
  30. newint[]{android.R.id.text1,android.R.id.text2},//父list的数据绑定到的view
  31. childData,//子list的数据
  32. android.R.layout.simple_expandable_list_item_2,
  33. newString[]{NAME,IS_EVEN},
  34. newint[]{android.R.id.text1,android.R.id.text2}
  35. );
  36. setListAdapter(mAdapter);
  37. }
  38. }

注意:android.R.layout.simple_expandable_list_item_1:表示只显示一个TextView的数据,即R.id.text1

android.R.layout.simple_expandable_list_item_2:表示显示二个TextView的数据,即R.id.text1,R.id,text2

android.R.layout.simple_expandable_list_item_2.xml(在R.layout中)文件的布局如下:

view plain copy to clipboard print ?
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="vertical">
  6. <TextViewandroid:id="@+id/text1"
  7. android:textSize="16sp"
  8. android:textStyle="bold"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"/>
  11. <TextViewandroid:id="@+id/text2"
  12. android:textSize="16sp"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"/>
  15. </LinearLayout>

示例2—通过SimpleCussorTreeAdapter绑定数据:

view plain text-decoration: none; color: #a0a0a0; background-image: none; background-color: inherit; margin-top: 分享到: Android Handler详解 (转载) | java读取配置文件的几种方法
  • 2011-03-29 11:03
  • 浏览 945
  • 评论(0)
  • 分类:移动开发
  • 相关推荐
评论
发表评论

您还没有登录,请您登录后再发表评论

Jaycee
  • 浏览: 9824 次
  • 性别:
  • 来自: 福州
最近访客 更多访客>>
oushitian dylinshi126
文章分类
  • 全部博客 (16)
  • Java (5)
  • Android (5)
  • XML (1)
  • JQuery (0)
  • 数据库 (0)
  • JS (0)
  • Foo (0)
  • Struts (0)
  • Spring (1)
  • Hibernate (1)
  • UE (1)
  • JBPM (1)
社区版块
  • 我的资讯 (0)
  • 我的论坛 (0)
  • 我的问答 (0)
存档分类
  • 2011-06 (1)
  • 2011-05 (2)
  • 2011-03 (1)
  • 更多存档...
最新评论
  • oushitian: ...
    extjs组件添加事件监听的三种方式

更多相关文章

  1. android 蓝牙、低功耗BLE开发问题总结
  2. Android动态刷新listview中的数据
  3. android分页查询垃圾短信数据库信息
  4. Android(安卓)ExpandableListActivity 学习笔记
  5. android 读取网络在传输数据时的状态
  6. Android自定义对话框
  7. android 滑动加载数据
  8. android sqlite应用
  9. mybatisplus的坑 insert标签insert into select无参数问题的解决

随机推荐

  1. Android数据存储之文件存储
  2. Android之內置、外置SDCard
  3. android:布局参数,控件属性及各种xml的作
  4. android 基于jsBridge实现js交互时对webv
  5. 2012年度工作总结
  6. Android(安卓)View和GLSurfaceView使用Op
  7. android面试
  8. 关于使用Android NDK编译ffmpeg
  9. Android(安卓)Jetpack架构组件(一)带你了解
  10. Android(安卓)写输入编辑框增加@功能,@相