作者:生命在于创新_475 | 来源:互联网 | 2023-09-01 16:13
2019独角兽企业重金招聘Python工程师标准˃˃˃packagecom.example.expandable;importjava.util.ArrayList;im
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
childsItem = new ArrayList(); 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 groupList; private List> childList; private LayoutInflater layoutInflater; public MyAdapter(Context context, List groupList, List> 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; }}