android - ExpandableListView; When I click on first group's switchCompat, other group's switchCompat click on and vise versa -
i created expandablelistview have had many errors. "flat list position of unknown type". don't error when click on group's switchcompact child, other group's switchcompact child clicked. adapter below:
public class expandablelistadapter extends baseexpandablelistadapter { private string company_name_array[] = { "po" , "opet" , "shell" , "bp" }; private int company_icon_array[] = { r.drawable.po, r.drawable.opet, r.drawable.shell, r.drawable.bp }; static public list<string> stationlist; static public list<string> fuellist; static public boolean density; private imageview image1; private imageview image2; private textview text1; private textview text2; private context _context; private list<string> _listdataheader; // header titles // child data in format of header title, child title private hashmap<string, list<string>> _listdatachild; public expandablelistadapter(context context, list<string> listdataheader, hashmap<string, list<string>> listchilddata) { this._context = context; this._listdataheader = listdataheader; this._listdatachild = listchilddata; stationlist = new arraylist<>(); fuellist = new arraylist<>(); density = false; } public expandablelistadapter() { } @override public object getchild(int groupposition, int childposititon) { return this._listdatachild.get(this._listdataheader.get(groupposition)) .get(childposititon); } @override public long getchildid(int groupposition, int childposition) { return childposition; } @override public view getchildview(int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { final string childtext = (string) getchild(groupposition, childposition); viewholder holder; if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_item2, null); /*holder = new viewholder(); holder.toogle = (switchcompat) convertview.findviewbyid(r.id.switch2); holder.toogle.settext(childtext);*/ } /*else { holder = new viewholder(); holder.toogle = (switchcompat) convertview.findviewbyid(r.id.switch2); holder.toogle.settext(childtext); } holder.toogle.settext(childtext);*/ switchcompat toogle = (switchcompat) convertview.findviewbyid(r.id.switch2); toogle.settext(childtext); if(groupposition == 0) { /*imageview image = (imageview) convertview.findviewbyid(r.id.company_icon); typedarray img = this._context.getresources().obtaintypedarray(r.array.company_icon); for(int = 0; < company_name_array.length; i++) { if(company_name_array[i].contains(childtext) && childtext.contains(company_name_array[i])) { image.setbackgroundresource(img.getresourceid(i, -1)); break; } }*/ clicktoogle(toogle); } else if(groupposition == 1)//il { } else if(groupposition == 2)//akaryakıt { clicktooglefuel(toogle); } else if(groupposition == 3)//yoğunluk { clicktoogledensity(toogle); } //txtlistchild.settext(childtext); return convertview; } @override public int getchildrencount(int groupposition) { return this._listdatachild.get(this._listdataheader.get(groupposition)) .size(); } public static class viewholder { public switchcompat toogle; } @override public object getgroup(int groupposition) { return this._listdataheader.get(groupposition); } @override public int getgroupcount() { return this._listdataheader.size(); } @override public long getgroupid(int groupposition) { return groupposition; } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { string headertitle = (string) getgroup(groupposition); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_group, null); } textview lbllistheader = (textview) convertview .findviewbyid(r.id.lbllistheader); lbllistheader.settypeface(null, typeface.bold); lbllistheader.settext(headertitle); return convertview; } @override public boolean hasstableids() { return false; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } public list<string> getarraylist() { return stationlist; } }
Comments
Post a Comment