使用BaseExpandableListAdapter 可以实现所谓的可折叠的列表,例如QQ里好友的分组的功能。
BaseExpandableListAdapter与BaseAdapter的基本原理是一样的,只不过在传入list的时候,要传入两组,一组是groupArray ,一组时childArray,前者用于组名(类似QQ的好友、同学、朋友),后者的每个元素都是一组子数据(类似QQ同学中的张三,李四的集合),实现adapter
public class ExpandableAdapter extends BaseExpandableListAdapter{ private LinkedList<TeacherSumGroupsModel> groupArray; private List<LinkedList<TeacherSumGroupDetailModel>> childArray; private Context context; private LayoutInflater inflater; public ExpandableAdapter(Context context,LinkedList<TeacherSumGroupsModel> courseGroupList, List<LinkedList<TeacherSumGroupDetailModel>> childArray){ inflater = ((Activity) context).getLayoutInflater(); this.groupArray = courseGroupList; this.childArray = childArray; } public int getGroupCount() { // TODO Auto-generated method stub return groupArray.size(); } public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return childArray.get(groupPosition).size(); } public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return groupArray.get(groupPosition); } public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childArray.get(groupPosition).get(childPosition); } public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } public boolean hasStableIds() { // TODO Auto-generated method stub return false; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView title; if(convertView == null){ convertView = inflater.inflate(R.layout.simple_listview_item, parent, false); } title = (TextView) convertView.findViewById(R.id.simple_listview_textview); String t = " "+groupArray.get(groupPosition).getname(); title.setText(t); return convertView; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView title; if(convertView == null){ convertView = inflater.inflate(R.layout.simple_listview_item, parent, false); } title = (TextView) convertView.findViewById(R.id.simple_listview_textview); String account = childArray.get(groupPosition).get(childPosition).getAccount(); String name = childArray.get(groupPosition).get(childPosition).getName(); String t = account +" "+name; Log.e("sumlist", "info is " +t); title.setText(t); return convertView; } public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } }
代码摘自现在的某个项目。
类似与BaseAdapter的关键getView方法,这里比较重要的是getGroupView和getChildView方法,其实内部实现都是类似的。
相关推荐
主要介绍了Android基于BaseExpandableListAdapter实现的二级列表仿通话记录功能,结合具体实例形式分析了Android实现通话记录功能的布局与功能相关操作技巧,需要的朋友可以参考下
Android BaseExpandableListAdapter 教程
NULL 博文链接:https://xieruilin.iteye.com/blog/726494
可以向QQ好友列表一样,可以有二级列表,使用的是android控件BaseExpandableListAdapter。
在某些android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的。接触Android,也才一年的时间,大部分时间花在工作上(解bug。。。),界面上开发很少参与。自己维护的系统应用里,有个...
创建ExpandableListView并使用BaseExpandableListAdapter派生类填充它
http://blog.csdn.net/richiezhu/article/details/50906152 BaseExpandableListAdapter
在某些android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的。接触Android,也才一年的时间,大部分时间花在工作上(解bug。。。),界面上开发很少参与。自己维护的系统应用里,有个...
android listview SQLite BaseExpandableListAdapter 图片切割 bitmap
利用ExpandableListView实现多级目录的显示。
当用BaseExpandableListAdapter来实现二级树形菜单时,父项(getGroupView())和子项(getChildView())都是使用TextView。当要实现三级树形菜单时,子项(getChildView())就必须使用ExpandableList了。另
包括:android gravity 和 android layout_Gravity,Bundle,ContentResolver,cursor,Fragments ,Fragments,inflater ,Fragment,数据查询query函数参数解析, 【Cursor】 类的介绍,android 获得通话记录,Handler ,...
好友列表的一个小例子,使用BaseExpandableListAdapter,完成的资源的复用,很简单很漂亮的例子
Android 中使用ExpandableListView 实现分组 一个视图显示垂直滚动两级列表中的条目。这不同于列表视图,允许两个层次,类似于QQ的好友分组。要实现这个效果的整体思路为: 1.要给ExpandableListView 设置适配器,...
import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.TextView; import android.widget.Toast; ...
Android开发模拟QQ扩展列表功能的框架,简单易懂,方便使用,比重写 BaseExpandableListAdapter更方面,更灵活可以自定义listView布局!
使用ExpandableListAdapter实现购物车产品列表,然后通过CheckBox来选择产品。 弹出Layout来选择数量。值得产考!