java - How to set no indicator for the group having zero child in Expandable ListView? -
i want set no indicator groups having 0 child .i have used expandable list view .this screenshot initial layout.initially groups 0 child have no indicator .but expand group definite number of childs groups no child starts showing indicator .
mainactivity.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:opendrawer="start"> <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.navigationview android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitssystemwindows="true" app:headerlayout="@layout/nav_header_main" android:clickable="true"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <expandablelistview android:id="@+id/exp_list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="160dp" android:indicatorright="?android:attr/expandablelistpreferreditemindicatorright" android:background="@android:color/white" android:footerdividersenabled="true" android:groupindicator="@null"> </expandablelistview> <!--<listview--> <!--android:background="@android:color/white"--> <!--android:id="@+id/menulist"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="match_parent"--> <!--android:layout_margintop="10dp" />--> </linearlayout> </android.support.design.widget.navigationview> </android.support.v4.widget.drawerlayout>
listheader.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginleft="5dp" android:orientation="horizontal"> <imageview android:id="@+id/iconimage" android:layout_width="40dp" android:layout_height="40dp" android:padding="10dp"/> <textview android:id="@+id/submenu" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:textcolor="#000000" android:textsize="16sp" android:gravity="center_vertical" /> </linearlayout> </linearlayout>
expandablelistadapter.java
package com.global.market; import android.content.context; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.expandablelistview; import android.widget.imageview; import android.widget.textview; import java.util.hashmap; import java.util.list; /** * created samarth on 17-jul-16. */ public class expandablelistadapter extends baseexpandablelistadapter { private context mcontext; private list<expandedmenumodel> mlistdataheader; // header titles // child data in format of header title, child title private hashmap<expandedmenumodel, list<string>> mlistdatachild; expandablelistview expandlist; public expandablelistadapter(context context, list<expandedmenumodel> listdataheader, hashmap<expandedmenumodel, list<string>> listchilddata, expandablelistview mview) { this.mcontext = context; this.mlistdataheader = listdataheader; this.mlistdatachild = listchilddata; this.expandlist = mview; } @override public int getgroupcount() { int = mlistdataheader.size(); log.d("groupcount", string.valueof(i)); return this.mlistdataheader.size(); } @override public int getchildrencount(int groupposition) { int childcount = 0; if (groupposition<2) { childcount = this.mlistdatachild.get(this.mlistdataheader.get(groupposition)) .size(); } return childcount; } @override public object getgroup(int groupposition) { log.d("group",groupposition+""); return this.mlistdataheader.get(groupposition); } @override public object getchild(int groupposition, int childposition) { // log.d("child", mlistdatachild.get(this.mlistdataheader.get(groupposition)) // .get(childposition).tostring()); return this.mlistdatachild.get(this.mlistdataheader.get(groupposition)) .get(childposition); } @override public long getgroupid(int groupposition) { return groupposition; } @override public long getchildid(int groupposition, int childposition) { return childposition; } @override public boolean hasstableids() { return false; } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { expandedmenumodel headertitle = (expandedmenumodel) getgroup(groupposition); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this.mcontext .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.listheader, null); } textview lbllistheader = (textview) convertview .findviewbyid(r.id.submenu); imageview headericon = (imageview) convertview.findviewbyid(r.id.iconimage); // lbllistheader.settypeface(null, typeface.bold); lbllistheader.settext(headertitle.geticonname()); headericon.setimageresource(headertitle.geticonimg()); if (isexpanded && getchildrencount(groupposition)>0) { lbllistheader.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.collapse, 0); } else if(getchildrencount(groupposition)>0){ // if group not expanded change text normal // , change icon lbllistheader.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.expand, 0); } return convertview; } @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) { final string childtext = (string) getchild(groupposition, childposition); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this.mcontext .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_submenu, null); } textview txtlistchild = (textview) convertview .findviewbyid(r.id.submenu); txtlistchild.settext(childtext); return convertview; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } }
i think add icon in groupview. then, during getgroupview()
, check how many child view group have , decide whether display "empty" icon
group view layout:
<linearlayout> <linearlayout ...> <imageview .../> <textview ... /> <imageview> <!-- imageview icon show group empty --> android:id="@+id/empty_group_icon" android:visibility="invisible" </imageview> </linearlayout> </linearlayout>
and inside getgroupview()
@override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { ... if(getchildrencount(groupposition) > 0) convertview.findviewbyid(r.id.empty_group_icon).setvisibility(view.invisible); else convertview.findviewbyid(r.id.empty_group_icon).setvisibility(view.visible); return convertview; }
Comments
Post a Comment