android学习--ExpandableListActivity和SimpleExpandableListAdapter的使用
来源:互联网 发布:淘宝秒杀开挂 编辑:程序博客网 时间:2024/05/16 01:09
1 在布局文件中声明ExpandableListActivity控件main.xml
<ExpandableListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No Data"/>
2在布局文件中声明group样式group.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 设置一级条目样式 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/groupTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60dp"
android:paddingTop="1dp"
android:paddingBottom="10dp"
android:textSize="26sp"
android:text="No Data"/>
</LinearLayout>
3在布局文件中声明子项的样式child.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 设置二级条目的样式 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/childTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="50dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="20sp"
android:text="@string/nodata"/>
</LinearLayout>
4创建一个Activity ,继承自ExpandableListActivity
public class MainActivity extends ExpandableListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
5为group创建数据
List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
Map<String, String> group1 = new HashMap<String, String>();
group1.put("group", "group1");
Map<String, String> group2 = new HashMap<String, String>();
group2.put("group", "group2");
groups.add(group1);
groups.add(group2);
6为child创建数据
// 定义一个List,该List为第一个一级条目提供二级条目的数据
List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
Map<String, String> child1Data1 = new HashMap<String, String>();
child1Data1.put("child", "child1Data1");
Map<String, String> child1Data2 = new HashMap<String, String>();
child1Data2.put("child", "child1Data2");
child1.add(child1Data1);
child1.add(child1Data2);
// 定义一个List,该List为第二个一级条目提供二级条目的数据
List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> child2Data = new HashMap<String, String>();
child2Data.put("child", "child2Data");
child2.add(child1Data1);
// 定义一个List,该List用来存储所有的二级条目的数据
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2);
7生成一个SimpleExpandableListAdapter对象,设置给当前ExpandableListActivity
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
this, groups, R.layout.group, new String[] { "group" },
new int[] { R.id.groupTo }, childs, R.layout.child,
new String[] { "child" }, new int[] { R.id.childTo });
//将SimpleExpandableListAdapter对象设置给当前的ExpandableListActivity
setListAdapter(adapter);
- android学习--ExpandableListActivity和SimpleExpandableListAdapter的使用
- ExpandableListActivity的使用和SimpleExpandableListAdapter的使用
- android示例之ExpandableListActivity和SimpleExpandableListAdapter
- ListView的嵌套,ExpandableListActivity和SimpleExpandableListAdapter
- Android学习笔记(十八)——ExpandableListActivity与SimpleExpandableListAdapter
- Android学习笔记——ExpandableListActivity与SimpleExpandableListAdapter
- ExpandableListActivity的学习和使用
- android 中SimpleExpandableListAdapter的使用
- [Android] ExpandableListActivity的使用
- marsAndroid学习——常见控件ExpandableListActivityh和SimpleExpandableListAdapter的简单使用
- android startActivtyForResult以及ExpandableListActivity的使用
- Android ExpandableListActivity 学习笔记
- Android ExpandableListActivity 学习笔记
- ExpandableListActivity的使用
- ExpandableListActivity 的使用
- android学习笔记之ExpandableListActivity
- Android上 ExpandableListActivity及CursorTreeAdapter的使用简介
- Android上 ExpandableListActivity及CursorTreeAdapter的使用简介
- AngularJS第四篇
- Laptops codeforces
- 优先级教训
- map, string 强大的STL
- centos 6.5 无线网络消失问题
- android学习--ExpandableListActivity和SimpleExpandableListAdapter的使用
- 程序猿生存定律——选公司
- 今天天气不错啊
- 王朝云
- BroadcastReceiver使用
- android权限列表
- HDU 2564 饭卡 01背包 dp
- Hdu1159 - Common Subsequence - 动态规划
- drawable mdpi ldpi hdpi的区别