java - How to load child items while click parent item in ExpandableListView -
i new android, have expandablelistview in app. want load child items while click parent item. tried alot not working . please help.
my code here:
expandablelistadapter listadapter; expandablelistview explistview; list<string> listdataheader; hashmap<string, list<string>> listdatachild; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.faq, container, false); // listview explistview = (expandablelistview) view.findviewbyid(r.id.faqlist); preparelistdata(); listadapter = new expandablelistadapter(getactivity(),listdataheader,listdatachild); // setting list adapter explistview.setadapter(listadapter); // listview group expanded listener explistview.setongroupexpandlistener(this); return view; } private void preparedata(string s) { log.d("working:","yes"); listdatachild = new hashmap<string, list<string>>(); // adding child data list<string> top250 = new arraylist<string>(); if(s.equals("top 250")){ top250 = new arraylist<string>(); top250.add("the shawshank redemption godfather"); }else if(s.equals("now showing")){ top250 = new arraylist<string>(); top250.add("the conjuring welcome world of india"); }else if(s.equals("coming soon..")){ top250 = new arraylist<string>(); top250.add("2 guns of indias"); }else { top250 = new arraylist<string>(); top250.add("nothing"); } listdatachild.put(listdataheader.get(0), top250); // header, child data listdatachild.put(listdataheader.get(1), top250); listdatachild.put(listdataheader.get(2), top250); } private void preparelistdata() { listdataheader = new arraylist<string>(); listdatachild = new hashmap<string, list<string>>(); // adding child data listdataheader.add("top 250"); listdataheader.add("now showing"); listdataheader.add("coming soon.."); // adding child data list<string> top250 = new arraylist<string>(); top250.add("the shawshank redemption"); top250.add("the godfather"); top250.add("the godfather: part ii"); top250.add("pulp fiction"); top250.add("the good, bad , ugly"); top250.add("the dark knight"); top250.add("12 angry men"); list<string> nowshowing = new arraylist<string>(); nowshowing.add("the conjuring"); nowshowing.add("despicable me 2"); nowshowing.add("turbo"); nowshowing.add("grown ups 2"); nowshowing.add("red 2"); nowshowing.add("the wolverine"); list<string> comingsoon = new arraylist<string>(); comingsoon.add("2 guns"); comingsoon.add("the smurfs 2"); comingsoon.add("the spectacular now"); comingsoon.add("the canyons"); comingsoon.add("europa report"); listdatachild.put(listdataheader.get(0), top250); // header, child data listdatachild.put(listdataheader.get(1), nowshowing); listdatachild.put(listdataheader.get(2), comingsoon); } @override public void ongroupexpand(int groupposition) { preparedata(listdataheader.get(groupposition)); listadapter = new expandablelistadapter(getactivity(),listdataheader,listdatachild); listadapter.notifydatasetchanged(); // setting list adapter explistview.setadapter(listadapter); toast.maketext(getactivity().getapplicationcontext(),listdataheader.get(groupposition) + " expanded", toast.length_short).show(); }
thanks in advance!
Comments
Post a Comment