Android ExpandableListView展开列表控件使用实例

2019-12-10 20:02:23丽君

    {
        //子元素的View
        TextView tv=new TextView(context);
        tv.setText(objs.get(groupPosition).childs.get(childPosition));
        tv.setLayoutParams(new ExpandableListView.LayoutParams(ExpandableListView.LayoutParams.FILL_PARENT,ExpandableListView.LayoutParams.WRAP_CONTENT));
        return tv;
    }
 
    @Override
    public int getChildrenCount(int groupPosition)
    {
        // TODO Auto-generated method stub
        return objs.get(groupPosition).childs.size();
    }
 
    @Override
    public Object getGroup(int groupPosition)
    {
        // TODO Auto-generated method stub
        return objs.get(groupPosition);
    }
 
    @Override
    public int getGroupCount()
    {
        // TODO Auto-generated method stub
        return objs.size();
    }
 
    @Override
    public long getGroupId(int groupPosition)
    {
        // TODO Auto-generated method stub
        return groupPosition;
    }
 
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        //分组的View
        TextView tv=new TextView(context);
        tv.setText(objs.get(groupPosition).groupName);
        ExpandableListView.LayoutParams params=new ExpandableListView.LayoutParams(ExpandableListView.LayoutParams.FILL_PARENT,60);
        tv.setLayoutParams(params);
        return tv;
    }
 
    @Override
    public boolean hasStableIds()
    {
        // TODO Auto-generated method stub
        return false;
    }