在做三级列表的时候,用的是ExpandableListView里套一个ExpandableListView,由于里面的ExpandableListView把图标隐藏了……点又点不开,就以为是里面的ExpandableListView失效,弄了三小时,才想到把图标显示出来,,结果……已经打开了,郁闷得要死了,,,然后知道是因为没有位置的原因了……哎,,记下,别以后还杨白劳三个小时……
public class EGuideFourAdapter extends BaseExpandableListAdapter { private Context mContext; private List<NamedList> list; public EGuideFourAdapter(Context context, List<NamedList> list) { this.list = list; this.mContext = context; } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return list.get(groupPosition).getChildList().get(childPosition); } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } static public TextView getTextView(Context context) {// 控制所有级的菜单,如果各级有另外设置,实现的是另外的设置。 AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 90); TextView textView = new TextView(context); textView.setLayoutParams(lp); textView.setTextSize(17); textView.setTextColor(Color.BLACK); textView.setPadding(10, 5, 0, 5); textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); return textView; } /** * 三层树结构中的第二层是一个ExpandableListView */ public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (list.get(groupPosition).getChildList().get(childPosition) .getChildList().size() > 0) {// 该项是否有第三级 // 是 final ExpandableListView examGuidView = getExpandableListView(); examGuidView.setGroupIndicator(null); examGuidView.setPadding(pixelsToDip(mContext,25), 0, 0, 0); final ExamGuideAdapter examGuideAdapter = new ExamGuideAdapter( this.mContext, list.get(groupPosition).getChildList()); // list.get(groupPosition).getChildList()为第二级的list examGuidView.setAdapter(examGuideAdapter); // 点击第三级时, examGuidView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPositionTwo, int childPosition, long id) { // 获取第四级列表项 List<NamedList> eGlist = list.get(groupPosition) .getChildList().get(groupPositionTwo) .getChildList().get(childPosition).getChildList(); // 获取第三级标题 String title = list.get(groupPosition).getChildList() .get(groupPositionTwo).getChildList() .get(childPosition).getName(); if (eGlist.size() > 0) {// 第四级不是详细内容 Intent intent = new Intent(mContext, UIExamGuideFour.class); intent.putExtra("list", (Serializable) eGlist); intent.putExtra("title", title); mContext.startActivity(intent); } else { Intent intent = new Intent(mContext, UIExamGuideContent.class); intent.putExtra("title", title); mContext.startActivity(intent); } return false; } }); /** * 重点:没有这个方法第三级会没有位置,所以会看不到,误以为ExpandableListView失效 * 关键点:第二级菜单展开时通过取得节点数来设置第三级菜单的大小 */ examGuidView.setOnGroupExpandListener(new OnGroupExpandListener() { int i = 0; @Override public void onGroupExpand(int groupPosition) { i = (list.get(groupPosition).getChildList() .get(childPosition).getChildList().size() + 1) * 90 + 30; AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, i); examGuidView.setLayoutParams(lp); } }); /** * 第二级菜单回收时设置为标准Item大小 */ examGuidView .setOnGroupCollapseListener(new OnGroupCollapseListener() { @Override public void onGroupCollapse(int groupPosition) { AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 90); examGuidView.setLayoutParams(lp); } }); return examGuidView; } else { TextView textView = getTextView(mContext); ExamGuide named = (ExamGuide) list.get(groupPosition) .getChildList().get(childPosition); textView.setTextColor(Color.BLACK); textView.setText(named.getName()); // textView.setTag(temp[1]); // textView.setText(getChild(groupPosition, // childPosition).toString()); textView.setPadding(pixelsToDip(mContext,55), 0, 0, 0);// 第一个参数原来为: // myPaddingLeft+PaddingLeft // ,是设置第三级菜单文字离左边的距离。 return textView; } } public ExpandableListView getExpandableListView() { AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 90); ExpandableListView superTreeView = new ExpandableListView(mContext); superTreeView.setLayoutParams(lp); return superTreeView; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { TextView textView = getTextView(mContext); ExamGuide named = (ExamGuide) list.get(groupPosition); textView.setText(named.getName()); textView.setPadding(pixelsToDip(mContext,40), 0, 0, 0);// 第一个参数原来为:myPaddingLeft+(PaddingLeft>>1) // ,是设置第二级菜单文字离左边的距离。 textView.setTextColor(Color.BLACK); return textView; } //像素转dip解决分辨率问题 private int pixelsToDip(Context context,int Pixels) { int dip=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Pixels, context.getResources().getDisplayMetrics()); return dip; } /** * 第二级点击打开第三级 * * @param examGuidView * @param groupPosition */ public void clickEvent(ExpandableListView examGuidView, int groupPosition) { examGuidView.expandGroup(groupPosition); } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return list.get(groupPosition).getChildList().size(); } @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return list.get(groupPosition); } @Override public int getGroupCount() { // TODO Auto-generated method stub return list.size(); } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public boolean isChildSelectable(int p, int id) { // TODO Auto-generated method stub return true; }
相关推荐
android ExpandableListView三级菜单的使用,多级菜单下拉与隐藏,ExpandableListView的简单使用
android ExpandableListView 四级树形目录 可无限延伸。
Android之ExpandableListView笔记
Android ExpandableListView双层嵌套实现三级树形菜单
Android之ExpandableListView控件的使用
CommentWithReplyView-master 基于ExpandableListView实现评论和回复的功能。 > 说明 ...处理了NestedScrollView、ExpandableListView和CoordinatorLayout的嵌套问题 点击某条评论,即可@ta进行回复
Android实现自定义适配器的ExpandableListView示例,准备一级列表中显示的数据:2个一级列表,分别显示"group1"和"group2",准备第一个一级列表中的二级列表数据:两个二级列表,分别显示"childData1"和"childData2",...
NULL 博文链接:https://geyubin.iteye.com/blog/1187831
本demo实现功能为:Expandablelistview子项checkBox先获取已选择状态,在次过程中可修改子项选择,最终提交选择子类的项,并打印相关数据
Android的ExpandableListView,可以用来实现一级二级级联菜单,这是一个demo
android ExpandableListView简单例子
Android学习笔记(二五): 多信息显示-ExpandableListView的使用
实现二级列表下拉,如listview,自定义适配器,初学者可以学习下
android中ExpandableListView嵌套GridView的使用
Android 下拉刷新ExpandableListView。做了几个分组好友列表。是一些数组数据加进去测试的。可以一看。
基于Android中的ExpandableListView开发示例, 应用list集合类型
ExpandableListView中group和child自定义视图带CheckBox,实现child全选、部分选中功能,同时实现类似邮件群发的用户选择功能,选中的用户在EditText中显示,点击后移除. 更新: 1. ExpandableListView勾选后生成的...
Android自定义ExpandableListView实现二级列表
Android 利用dialog弹出 二级下拉列表 ExpandableListView+DialogLI。 利用dialog和ExpandableListView实现的一个弹出二级菜单项,并进行了封装,可在activity和fragment中随意调用。简单实用,兼容性好。 二级列表