1.layout ,和listview一样
<ExpandableListView android:id="@+id/glkclistview" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#83ffffff" android:dividerHeight="1dp"> </ExpandableListView>
2.使用
listView = (ExpandableListView) findViewById(R.id.glkclistview);
GuanLiKcAdapter adapter = new GuanLiKcAdapter(GuanLiKeCheng.this , Kecheng_ZiYuans.yishenghe , Kecheng_ZiYuans.weishenghe); listView.setAdapter(adapter);
传进去两组数据,然后adapter如下:
public class GuanLiKcAdapter extends BaseExpandableListAdapter { private Context context; private List<Map<String, Object>> yi = new ArrayList<Map<String, Object>>(); private List<Map<String, Object>> wei = new ArrayList<Map<String, Object>>(); private String[] group = new String[]{"未审核课程", "已审核课程"}; private Map<String , List<Map<String , Object>>> mmp = new HashMap<>();//直接用list操作无效 public GuanLiKcAdapter(Context context, List<Map<String, Object>> yishenghe, List<Map<String, Object>> weishenghe) { this.context = context; yi = yishenghe; wei = weishenghe; mmp.put(group[0] , wei); mmp.put(group[1] , yi); } @Override public int getGroupCount() { return group.length; } @Override public int getChildrenCount(int groupPosition) { return mmp.get(group[groupPosition]).size(); } @Override public Object getGroup(int groupPosition) { return group[groupPosition]; } @Override public Object getChild(int groupPosition, int childPosition) { return mmp.get(group[groupPosition]).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) { View view = LayoutInflater.from(context).inflate(R.layout.guanli_kc_group, null); TextView group = (TextView) view.findViewById(R.id.guanlikcgroup); group.setText(getGroup(groupPosition).toString()); return view; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.guanli_kc_child, null); TextView fl = (TextView) view.findViewById(R.id.kcchildfl); TextView mc = (TextView) view.findViewById(R.id.kcchildmc); TextView zjr = (TextView) view.findViewById(R.id.kcchildzjr); TextView jj = (TextView) view.findViewById(R.id.kcchildjj); TextView qx = (TextView) view.findViewById(R.id.kcchildqx); TextView time = (TextView) view.findViewById(R.id.kcchildsj); Map<String, Object> map = new HashMap<String, Object>(); map = (Map<String, Object>) getChild(groupPosition , childPosition); fl.setText(map.get("fl").toString()); mc.setText(map.get("bt").toString()); zjr.setText(map.get("zjr").toString()); jj.setText(map.get("lrjj").toString()); qx.setText(map.get("qx").toString()); time.setText(map.get("time").toString()); return view; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } }其中Groupview和Childview可以自定义