ExpandableListView的使用
来源:互联网 发布:回龙观 矩阵 付军 编辑:程序博客网 时间:2024/06/06 17:08
ExpandableListView的使用
效果图
布局
<ExpandableListView android:id="@+id/expandableListView" android:layout_width="match_parent" android:layout_height="match_parent" />
初始化
ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
填充数据
KongqwExpandableListviewAdapter kongqwExpandableListviewAdapter = new KongqwExpandableListviewAdapter(this);expandableListView.setAdapter(kongqwExpandableListviewAdapter);
Adapter
package com.example.kongqw.myapplication;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.TextView;import java.util.ArrayList;/** * Created by kongqw on 2015/12/21. */public class KongqwExpandableListviewAdapter extends BaseExpandableListAdapter { private Context mContext; private ArrayList<String> mGroups; private ArrayList<String> mChilds; // 构造方法 public KongqwExpandableListviewAdapter(Context context) { mContext = context; // 模拟初始化数据 mGroups = new ArrayList<String>(); mGroups.add("Group 1"); mGroups.add("Group 2"); mGroups.add("Group 3"); mGroups.add("Group 4"); mGroups.add("Group 5"); mChilds = new ArrayList<String>(); mChilds.add("Child 1"); mChilds.add("Child 2"); mChilds.add("Child 3"); mChilds.add("Child 4"); mChilds.add("Child 5"); mChilds.add("Child 6"); mChilds.add("Child 7"); mChilds.add("Child 8"); mChilds.add("Child 9"); mChilds.add("Child 10"); } @Override public int getGroupCount() { return mGroups.size(); } @Override public int getChildrenCount(int groupPosition) { return mChilds.size(); } @Override public Object getGroup(int groupPosition) { return mGroups.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return mChilds.get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View view = View.inflate(mContext, R.layout.expandable_group_item, null); TextView textView = (TextView) view.findViewById(R.id.group_item); textView.setText(mGroups.get(groupPosition)); return view; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View view = View.inflate(mContext, R.layout.expandable_child_item, null); TextView textView = (TextView) view.findViewById(R.id.child_item); textView.setText(mChilds.get(childPosition)); return view; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; }}
去掉箭头
expandableListView.setGroupIndicator(null);
默认展开
// 设置ExpandableListView默认是展开的for (int i = 0; i < kongqwExpandableListviewAdapter.getGroupCount(); i++) { expandableListView.expandGroup(i);}
Group不可点击
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { // TODO Auto-generated method stub return true; }});
TODO 复用
0 0
- ExpandableListView的使用
- ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- 转载:ExpandableListView的使用
- ExpandableListView的使用
- expandablelistview的使用
- Android ExpandableListView的使用
- ExpandableListView组件的使用
- ExpandableListView的基本使用
- ExpandableListView的使用
- ExpandableListView的使用示例
- ExpandableListView的使用
- ExpandableListView的使用总结
- Android ExpandableListView的使用
- ExpandableListView的使用
- Android ExpandableListView的使用
- ExpandableListview的使用介绍
- a different object with the same identifier value was already associated with the session
- 源码解析Android中View的layout布局过程
- 如何设计一门语言(九)——类型
- Java设计模式 工厂模式(Factory)
- SVM入门(十)将SVM用于多类分类
- ExpandableListView的使用
- 如何设计一门语言(十)——正则表达式与领域特定语言(DSL)
- 文本分类入门(十一)特征选择方法之信息增益
- 如何设计一门语言(十一)——删减语言的功能
- 百度地图API 云存储·LBS.云 VO类封装(Java)
- zookeeper安装和应用场合(名字,配置,锁,队列,集群管理)
- 文本分类入门(番外篇)特征选择与特征权重计算的区别
- 校招android开发岗知识点总结
- 遮挡描边(原理篇)