首页 > 编程知识 正文

定义多级列表怎么应用全文,word怎么定义多级列表

时间:2023-05-04 23:59:56 阅读:173214 作者:4731

2019独角兽企业重金招聘Python工程师标准

packagecom.example.expandable; importjava.util.ArrayList; importjava.util.List; importandroid.app.Activity; importandroid.os.Bundle; importandroid.view.View; import Android.widget.expandable listview; import Android.widget.expandable listview.onchildclicklistener; import Android.widget.expandable listview.ongroupclicklistener; importandroid.widget.Toast; publicclassmainactivityextendsactivity { privateexpandablelistviewexpandablelistview; 私有列表字符串组列表; 权限列表列表stringchildlist; 权限适配器; @ overrideprotectedvoidoncreate (bundlesavedinstancestate ) super.oncreate ) savedinstancestate; setcontentview (r.layout.activity _ main; expandable listview=(expandable listview ) findviewbyid ) r.id.expandablelistview; groupList=newArrayListString; child list=newarraylistliststring (; initDatas (; adapter=newmyAdapter(this,groupList,childList ); expandable listview.set adapter (adapter; expandable listview.setgroupindicator (get resources ).get drawable (r.drawable.expand _ select ); expandable listview.setongroupclicklistener (newongroupclicklistener ) { @ overridepublicbooleanongroupclick (expandablelelelelelelelick ) intgroupPosition,longid (toast.maketext (getapplicationcontext ),grouplist.get ) groupposition ),toast.lengtion 返回假; (); expandable listview.setonchildclicklistener (newonchildclicklistener ({ @ overridepublicbooleanonchildclick ) ) intgroupPosition,intchildPosition,longid (toast.maketext (getapplicationcontext (,childlist.get ) grouppositiontiontext ) (); }privatevoidinitDatas () {updateDatas )、newstring )、刘德华、张学友、郭富城); updateDatas (《感兴趣的女明星》、newstring () )、《刘亦菲》、《张馨予》、《郭采洁》); }privatevo

id updateDatas(String groupItem, String[] childs) {        groupList.add(groupItem);        List<String> childsItem = new ArrayList<String>();        for (String item : childs) {            childsItem.add(item);        }        childList.add(childsItem);    }} package com.example.expandable;import java.util.List;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.TextView;public class MyAdapter extends BaseExpandableListAdapter {    private Context context;    private List<String> groupList;    private List<List<String>> childList;    private LayoutInflater layoutInflater;        public MyAdapter(Context context, List<String> groupList,            List<List<String>> childList) {        this.context = context;        this.groupList = groupList;        this.childList = childList;        this.layoutInflater = LayoutInflater.from(context);    }    @Override    public int getGroupCount() {        // TODO Auto-generated method stub        return groupList.size();    }    @Override    public int getChildrenCount(int groupPosition) {        return childList.get(groupPosition).size();    }    @Override    public Object getGroup(int groupPosition) {        // TODO Auto-generated method stub        return groupList.get(groupPosition);    }    @Override    public Object getChild(int groupPosition, int childPosition) {        // TODO Auto-generated method stub        return childList.get(groupPosition).get(childPosition);    }    @Override    public long getGroupId(int groupPosition) {        // TODO Auto-generated method stub        return groupPosition;    }    @Override    public long getChildId(int groupPosition, int childPosition) {        // TODO Auto-generated method stub        return childPosition;    }    @Override    public boolean hasStableIds() {        return false;    }    @Override    public View getGroupView(int groupPosition, boolean isExpanded,            View convertView, ViewGroup parent) {        if (convertView==null) {            convertView = layoutInflater.inflate(R.layout.group, parent,false);        }        TextView textView = (TextView) convertView.findViewById(R.id.tv_group);        textView.setText(groupList.get(groupPosition));        return convertView;    }    @Override    public View getChildView(int groupPosition, int childPosition,            boolean isLastChild, View convertView, ViewGroup parent) {        if (convertView==null) {            convertView = layoutInflater.inflate(R.layout.child, null);        }        TextView textView = (TextView) convertView.findViewById(R.id.tv_child);        textView.setText(childList.get(groupPosition).get(childPosition));        return convertView;    }    /**     * 返回值为true时   对child做出响wgdgk/    @Override    public boolean isChildSelectable(int groupPosition, int childPosition) {        return true;    }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。