Expand 二级目录集合实现的
2017-05-03 21:01
176 查看
public class MainActivity extends Activity { private ExpandableListView pand; private ArrayList<Bean> beans; private ArrayList<childBean> childB; private MyExpand expand; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pand = (ExpandableListView) findViewById(R.id.pand); // 添加集合 beans = new ArrayList<Bean>(); childB = new ArrayList<childBean>(); childBean ch1 = new childBean(R.drawable.ic_launcher, "一点儿都不好玩儿"); childBean ch2 = new childBean(R.drawable.ic_launcher, "你在骗人"); childBean ch3 = new childBean(R.drawable.ic_launcher, "我要回家"); childB.add(ch3); childB.add(ch2); childB.add(ch1); Bean bean1 = new Bean("我的好友", childB); Bean bean2 = new Bean("我的好友", childB); Bean bean3 = new Bean("我的好友", childB); Bean bean4 = new Bean("我的好友", childB); Bean bean5 = new Bean("我的好友", childB); beans.add(bean5); beans.add(bean4); beans.add(bean3); beans.add(bean2); beans.add(bean1); expand = new MyExpand(); pand.setAdapter(expand); } class MyExpand extends BaseExpandableListAdapter { private TextView group; private TextView child; @Override public int getGroupCount() { return beans.size(); } @Override public int getChildrenCount(int groupPosition) { return beans.get(groupPosition).getList().size(); } @Override public Object getGroup(int groupPosition) { return beans.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return beans.get(groupPosition).getList().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(MainActivity.this, R.layout.group, null); group = (TextView) convertView.findViewById(R.id.group); } group.setText(beans.get(groupPosition).getName().toString()); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(MainActivity.this, R.layout.child, null); child = (TextView) convertView.findViewById(R.id.child); } child.setText(beans.get(groupPosition).getList().get(childPosition) .getText().toString()); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } } }
相关文章推荐
- Expand 二级目录 集合实现的
- css 二级菜单 实现代码集合 修正版
- ExpandInfoAdapter实现二级列表显示
- 操作系统: 二级目录文件系统的实现(c/c++语言)
- [原创]java WEB学习笔记93:Hibernate学习之路---Hibernate 缓存介绍,缓存级别,使用二级缓存的情况,二级缓存的架构集合缓存,二级缓存的并发策略,实现步骤,集合缓存,查询缓存,时间戳缓存
- 自动建站.实现虚拟二级目录
- RecyclerView实现二级目录显示---item可伸展收缩的RecyclerVoew
- Java基础知识:Java实现Map集合二级联动3
- Java基础知识:Java实现Map集合二级联动2
- MyBatis系列目录--5. MyBatis一级缓存和二级缓存(redis实现)
- Asp.net多域名如何实现二级域名子目录跳转
- Android:如何在ListView中嵌套ListView (如何实现二级目录结构?)(2)
- 关于二级目录拖拽排序的实现(源码示例下载)
- Java基础知识:Java实现Map集合二级联动4
- asp.net编程获取项目根目录实现方法集合
- css 二级菜单 实现代码集合 修正版
- 关于二级目录拖拽排序的实现(源码示例下载)
- Java实现Map集合二级联动示例
- Java实现Map集合二级联动示例-----带界面--------------
- Java实现Map集合二级联动