ExpandableListView实现多级菜单
2014-12-16 17:31
549 查看
1.数据为树形结构。
2.在BaseExpandableListAdapter的getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)方法中,判断子节点是否为叶子节点。
如果是子节点是叶子节点,生成子界面。如果是树节点,则生成ExpandableListView。形成递归。
@Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if(getChildType(groupPosition, childPosition)==TYPE_DEPT){ int deptposition = childPosition-mData.get(groupPosition).getPoliceOfficers().size(); convertView = mInflater.inflate(R.layout.police_subdept_item_layout, null); ExpandableListView expandableListView = (ExpandableListView) convertView.findViewById(R.id.ex_lv_contacts); PoliceDept subDept = mData.get(groupPosition).getPoliceDepts().get(deptposition); List<PoliceDept> data = new ArrayList<PoliceDept>(); data.add(subDept); final ContactsExpandableAdapter adapter = new ContactsExpandableAdapter(mContext,data); expandableListView.setAdapter(adapter); expandableListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { PoliceOfficer policeOfficer = adapter.getChild(groupPosition, childPosition); LogUtils.e("", ""+policeOfficer.getName()); return false; } }); }else{ ChildViewHolder holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.police_officer_item_layout, null); holder = new ChildViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.tv_police_officer_name); holder.mobilePhoe = (TextView) convertView.findViewById(R.id.tv_police_officer_position); holder.phone = (TextView) convertView.findViewById(R.id.tv_police_officer_phone); convertView.setTag(holder); } else { holder = (ChildViewHolder) convertView.getTag(); } holder.name.setText(getChild(groupPosition, childPosition) .getName()); holder.mobilePhoe.setText(getChild(groupPosition, childPosition) .getPosition()); holder.phone.setText(getChild(groupPosition, childPosition) .getPhone()); } return convertView; }
3.子节点的ExpandableListView必须经过处理,才能展开。
import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * 自定义的ExpandableListView * @author lyixin@linewell.com * @since 2014年12月16日 */ public class CustExpListview extends ExpandableListView { public CustExpListview(Context context) { super(context); } public CustExpListview(Context context, AttributeSet attrs) { super(context, attrs); } protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //解决嵌套的ExpandableListView不能展开问题 heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
相关文章推荐
- 用XSL与XML实现多级菜单
- 用popup实现右键多级菜单
- 单片机c语言下lcd多级菜单的一种实现方法
- Android提高十七篇之多级树形菜单的实现
- Android提高十七篇之多级树形菜单的实现
- 用XSL与XML实现多级树形菜单
- Android提高十七篇之多级树形菜单的实现
- Android提高十七篇之多级树形菜单的实现
- php ajax实现的二级(多级)联动菜单(2008-10-21,11:36:08)
- jquery ajax 多级select 菜单联动加载实现
- 用PHP实现多级树型菜单
- Javascript实现网页上的多级菜单
- JS实多级联动下拉菜单类,简单实现省市区联动菜单!
- ExtJs多级联动菜单的一种实现
- 使用Django和MochiKit实现多级联动菜单
- 用PHP实现多级树型菜单
- 用prototype实现的简单小巧的多级联动菜单
- 用PHP实现多级树型菜单
- Android提高十七篇之多级树形菜单的实现
- Android提高十七篇之多级树形菜单的实现