BaseExpandableListAdapter主要用于类似于qq分组这样的显示的适配器
BaseExpandableListAdapteview适用于类似qq分组的模式
//关键代码是这个可扩展的listview适配器
class ExAdapter extends BaseExpandableListAdapter {
Context context;
public ExAdapter(Context context) {
super();
this.context = context;
}
//得到大组成员总数
public int getGroupCount() {
// TODO Auto-generated method stub
return groupData.size();
}
//得到小组成员总数
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return childData.get(groupPosition).size();
}
//得到大组成员名称
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groupData.get(groupPosition).get(GROUP_TEXT).toString();
}
//得到小组成员名称
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childData.get(groupPosition).get(childPosition).get(CHILD_NAME).toString();
}
//得到大组成员的id
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
//得到小组成员的id
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
/**
* Indicates whether the child and group IDs are stable across changes
* to the underlying data. 表明大組和小组id是否稳定的更改底层数据。
*
* @return whether or not the same ID always refers to the same object
* @see Adapter#hasStableIds()
*/
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
//得到大组成员的view
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
if(view == null) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.member_listview2, null);
}
TextView title = (TextView)view.findViewById(R.id.content_001);
title.setText(getGroup(groupPosition).toString()); //设置最大组成员名称
ImageView image = (ImageView)view.findViewById(R.id.tubiao); //是否展开大组的图标
if(isExpanded) //大组展开时
image.setBackgroundResource(R.drawable.hero);
else
image.setBackgroundResource(R.drawable.ic_launcher);
return view;
}
//得到小组成员的view
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
if(view == null) {
LayoutInflater inflater = LayoutInflater.from(context);
view = inflater.inflate(R.layout.member_childitem2, null);
}
final TextView title = (TextView)view.findViewById(R.id.child_name);
title.setText(childData.get(groupPosition).get(childPosition).get(CHILD_NAME).toString()); //大标题
final TextView title2 = (TextView)view.findViewById(R.id.child_text);
title2.setText(childData.get(groupPosition).get(childPosition).get(CHILD_TEXT).toString()); //小标题
return view;
}
//得到小组成员是否被选择
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}