使用ExpandableListActivity显示扩展列表
2013-05-20 12:17
211 查看
使用ExpandableListActivity显示扩展列表
上次我们讲了使用SQLite数据库存储数据,那么我们存储在SQLite数据库中的数据如和将它显示在Android客户端呢?这里我们使用ExpandableListActivity将数据显示在Android客户端。
我们的工程使用上次SQLite存储数据的那个例子使用SQLite数据库存储数据,完成效果:
之前SQLite数据库中的数据:
上次我们讲了使用SQLite数据库存储数据,那么我们存储在SQLite数据库中的数据如和将它显示在Android客户端呢?这里我们使用ExpandableListActivity将数据显示在Android客户端。
我们的工程使用上次SQLite存储数据的那个例子使用SQLite数据库存储数据,完成效果:
之前SQLite数据库中的数据:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ExpandableListView android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>MainActivity类:
public class MainActivity extends ExpandableListActivity { private ExpandableListAdapter myAdapter; private DBOpenHelper dbOpenHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); dbOpenHelper = new DBOpenHelper(MainActivity.this); // 查询组数据 Cursor groupCursor = queryGroupCursor(); myAdapter = new MyExpandableListerAapter(MainActivity.this, groupCursor, android.R.layout.simple_expandable_list_item_1, android.R.layout.simple_expandable_list_item_1, new String[] { "typeName" }, new int[] { android.R.id.text1 }, new String[] { "name" }, new int[] { android.R.id.text1 }); setListAdapter(myAdapter); } private Cursor queryGroupCursor() { SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); Cursor groupCursor = db.query("MenuTbl", new String[] { "distinct typeName" }, null, null, null, null, null); return groupCursor; } public class MyExpandableListerAapter extends SimpleCursorTreeAdapter { public MyExpandableListerAapter(Context context, Cursor cursor, int groupLayout, int childLayout, String[] groupFrom, int[] groupTo, String[] childFrom, int[] childTo) { super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom, childTo); } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { String typeName = groupCursor.getString(groupCursor .getColumnIndex("typeName")); System.out.println(typeName); // 查询子数据 Cursor childCursor = queryChildCursor(typeName); return childCursor; } @Override public long getChildId(int groupPosition, int childPosition) { Cursor childCursor = (Cursor) getChild(groupPosition, childPosition); return childCursor.getLong(0); } @Override public long getGroupId(int groupPosition) { Cursor groupCursor = (Cursor) getGroup(groupPosition); return groupCursor.getLong(0); } private Cursor queryChildCursor(String typeName) { SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); Cursor childCursor = db.query("MenuTbl", new String[] { "name" }, "typeName=\"" + typeName + "\"", null, null, null, null); return childCursor; } } }
相关文章推荐
- 利用ListItem.Expandable来显示一个可以扩展的列表
- ExpandableListActivity 关于group和child列表长按事件,显示不同的操作列表
- 第 9 章 使用 ListFragment 显示列表
- marsAndroid学习——常见控件ExpandableListActivityh和SimpleExpandableListAdapter的简单使用
- android:使用BaseExpandableListAdapter实现可折叠的列表
- 使用ListFragment显示列表
- 按首字母分类并排序显示的列表(二)--给BaseExpandableListAdapter提供数据的HashList
- UI组件之AdapterView及其子类(六)ExpandableListView组件和ExpandableListActivity的使用
- [Android] ExpandableListActivity的使用
- 扩展BaseExpandableListAdapter实现自定义展开式列表
- ExpandableListActivity列表嵌套列表
- 使用ExpandableListView和ExpandableListAdapter实现分组列表
- Android开发之ExpandableListView扩展(BaseExpandableListAdapter的使用)(完整版)
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
- ExpandableListView 和 ExpandableListActivity的使用及数据更新
- Android Fragment学习笔记(2) ----使用ListFragment显示列表(上)
- TabActivity,ActivityGroup,ExpandableListActivity,ListView联合使用问题解决。
- ExpandableListView使用(三)-ScrollView嵌套ExpandableListView,列表显示不全
- ExpandableListView / ExpandableListActivity 使用及数据更新
- ExpandableListView 和 ExpandableListActivity的使用及数据更新