ExpandableListview的简单使用

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可以自定义




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值