android学习笔记22:可展开的ListView
来源:互联网 发布:表结构列的删除的sql 编辑:程序博客网 时间:2024/06/08 07:47
http://blog.csdn.net/hn307165411/article/details/7173284
有时在写程序时,我们希望一个listview能展开其下的子类目,在android中可以通过使用ExpandAbleListView来实现,只需要在代码里为ExpandAbleListView设置一个ExpandAbleLIstAdapter的数据源即可。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <ExpandableListView
- android:id="@+id/list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:childIndicator="@drawable/icon"
- ></ExpandableListView>
- </LinearLayout>
- public class ExpandableListViewTest extends Activity
- {
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //创建一个BaseExpandableListAdapter对象
- ExpandableListAdapter adapter = new BaseExpandableListAdapter()
- {
- int[] logos = new int[]
- {
- R.drawable.sunyz_1,
- R.drawable.sunyz_6,
- R.drawable.sunyz_7
- };
- private String[] CDs = new String[]
- { "风筝", "完美的一天", "是时候"};
- private String[][] songs = new String[][]
- {
- { "绿光", "不是真的爱我", "爱情字典", "练习" },
- { "Honey Honey", "心愿", "明天晴天", "隐形人" },
- { "愚人的国度", "是时候" , "世说心语" }
- };
- //获取指定组位置、指定子列表项处的子列表项数据
- @Override
- public Object getChild(int groupPosition, int childPosition)
- {
- return songs[groupPosition][childPosition];
- }
- @Override
- public long getChildId(int groupPosition, int childPosition)
- {
- return childPosition;
- }
- @Override
- public int getChildrenCount(int groupPosition)
- {
- return songs[groupPosition].length;
- }
- private TextView getTextView()
- {
- //用于实现条目的虚拟列表的基类. 这里的列表没有空间的定义。 例如,该类的子类可以以网格的形式、走马灯的形式显示,或者作为堆栈等等
- AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT, 64); //设置宽和高
- TextView textView = new TextView(ExpandableListViewTest.this);
- textView.setLayoutParams(lp);
- textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
- textView.setPadding(36, 0, 0, 0);
- textView.setTextSize(20);
- return textView;
- }
- //该方法决定每个子选项的外观
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent)
- {
- TextView textView = getTextView();
- textView.setText(getChild(groupPosition, childPosition).toString());
- return textView;
- }
- //获取指定组位置处的组数据
- @Override
- public Object getGroup(int groupPosition)
- {
- return CDs[groupPosition];
- }
- @Override
- public int getGroupCount()
- {
- return CDs.length;
- }
- @Override
- public long getGroupId(int groupPosition)
- {
- return groupPosition;
- }
- //该方法决定每个组选项的外观
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent)
- {
- LinearLayout ll = new LinearLayout(ExpandableListViewTest.this);
- ll.setOrientation(0);
- ImageView logo = new ImageView(ExpandableListViewTest.this);
- logo.setImageResource(logos[groupPosition]);
- ll.addView(logo);
- TextView textView = getTextView();
- textView.setText(getGroup(groupPosition).toString());
- ll.addView(textView);
- return ll;
- }
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition)
- {
- return true;
- }
- @Override
- public boolean hasStableIds()
- {
- return true;
- }
- };
- ExpandableListView expandListView = (ExpandableListView)
- findViewById(R.id.list);
- expandListView.setAdapter(adapter);
- }
- }
0 0
- android学习笔记22:可展开的ListView
- android学习笔记22:可展开的ListView
- Android ExpandableListView 可展开的ListView
- Android开发之ExpandableListView: 可展开的ListView
- 按钮形式的可展开的listview
- ExpandableListView的使用,可展开的ListView
- ExpandableListView,可展开和折叠的ListView
- Android实现树状多层可展开收起ListView
- ExpandableListView(似listview中的item可展开)可展开的列表组件
- ExpendableListView(可展开的列表组件)笔记
- Android学习笔记(34)--- 可下拉ListView(ExpandableListView)的使用
- 带展开更多收起更多的可扩展的ListView
- 可展开(收缩)的列表ListView(ExpandableListView)
- 可点击展开的ListView--ExpandableListView
- ExpandableListView实现可展开的ListView(取自真实项目)
- ExpandableListView--------可展开的ListView(自定义箭头)
- android-ExpandableList可展开的list
- Android ExpandableListActivity实现可展开的activity
- C# string 转xml
- Android复习第1课:在代码中控制UI界面
- 没有人会对你的快乐负责,不久你便会知道,快乐得你自己寻找
- oracle用户解锁的三种办法
- 图的深度优先搜索 递归和非递归实现 c++版本
- android学习笔记22:可展开的ListView
- BOM、session、cookie
- 向优盘写RAW数据
- WinCE中命令行工具Viewbin简介
- cvCopy与cvCloneImage的区别
- c语言(基本运算)
- C++类实现最大数的输出
- 解决CHM文件打开无法显示网页的问题
- PHP 代码 review 细节 二