Android(安卓)ExpandableListActivity 学习笔记
16lz
2021-12-23
转载自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 ?- publicclassExpandableList3extendsExpandableListActivity{
- privatestaticfinalStringNAME="NAME";
- privatestaticfinalStringIS_EVEN="IS_EVEN";
- privateExpandableListAdaptermAdapter;
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- List<Map<String,String>>groupData=newArrayList<Map<String,String>>();
- List<List<Map<String,String>>>childData=newArrayList<List<Map<String,String>>>();
- for(inti=0;i<20;i++){
- Map<String,String>curGroupMap=newHashMap<String,String>();
- groupData.add(curGroupMap);
- curGroupMap.put(NAME,"Group"+i);
- curGroupMap.put(IS_EVEN,(i%2==0)?"Thisgroupiseven":"Thisgroupisodd");
- List<Map<String,String>>children=newArrayList<Map<String,String>>();
- for(intj=0;j<15;j++){
- Map<String,String>curChildMap=newHashMap<String,String>();
- children.add(curChildMap);
- curChildMap.put(NAME,"Child"+j);
- curChildMap.put(IS_EVEN,(j%2==0)?"Thischildiseven":"Thischildisodd");
- }
- childData.add(children);
- }
- //Setupouradapter
- mAdapter=newSimpleExpandableListAdapter(
- this,
- groupData,//存储父list的数据
- android.R.layout.simple_expandable_list_item_2,//父list的现实方式
- newString[]{NAME,IS_EVEN},//父list需要显示的数据
- newint[]{android.R.id.text1,android.R.id.text2},//父list的数据绑定到的view
- childData,//子list的数据
- android.R.layout.simple_expandable_list_item_2,
- newString[]{NAME,IS_EVEN},
- newint[]{android.R.id.text1,android.R.id.text2}
- );
- setListAdapter(mAdapter);
- }
- }
注意: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 ?- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextViewandroid:id="@+id/text1"
- android:textSize="16sp"
- android:textStyle="bold"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
- <TextViewandroid:id="@+id/text2"
- android:textSize="16sp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
- </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组件添加事件监听的三种方式
更多相关文章
- android 蓝牙、低功耗BLE开发问题总结
- Android动态刷新listview中的数据
- android分页查询垃圾短信数据库信息
- Android(安卓)ExpandableListActivity 学习笔记
- android 读取网络在传输数据时的状态
- Android自定义对话框
- android 滑动加载数据
- android sqlite应用
- mybatisplus的坑 insert标签insert into select无参数问题的解决