i want give adapter object has key value of object , arraylist of objects.
for instance
ingredient beef = new ingredient("beef"); ingredient cheese = new ingredient("cheese"); ingredient salsa = new ingredient("salsa"); ingredient tortilla = new ingredient("tortilla"); ingredient ketchup = new ingredient("ketchup"); ingredient bun = new ingredient("bun"); recipe taco = new recipe("taco", arrays.aslist(beef, cheese, salsa, tortilla)); recipe quesadilla = new recipe("quesadilla", arrays.aslist(cheese, tortilla)); recipe burger = new recipe("burger", arrays.aslist(beef, cheese, ketchup, bun)); recipes = arrays.aslist(taco, quesadilla, burger);
now how expandable adapter show group heading example taco, quesadilla, , burger. when expanded shows ingredients each? both need objects because next step in ingredients able select , deselect ingredients , pass new object.
my adapter
public class expandablelistadapter extends baseexpandablelistadapter { private context _context; private arraylist<recipe> _listdataheader; // header titles // child data in format of header title, child title private hashmap<recipe, list<string>> _listdatachild; //keep track of checks arraylist<arraylist<integer>> check_states = new arraylist<arraylist<integer>>(); public expandablelistadapter(context context, arraylist<recipe> listdataheader, hashmap<recipe, list<string>> listchilddata) { this._context = context; this._listdataheader = listdataheader; this._listdatachild = listchilddata; } @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); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_item_create_team_child, null); } final checkbox chk = (checkbox) convertview.findviewbyid(r.id.checkboxchild); chk.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked == true){ //_listdatachild.get(childposition) } } } ); textview txtlistchild = (textview) convertview .findviewbyid(r.id.teamnamechild); txtlistchild.settext(childtext); return convertview; } @override public int getchildrencount(int groupposition) { return this._listdatachild.get(this._listdataheader.get(groupposition)) .size(); } @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) { if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_item_create_team, null); } textview lbllistheader = (textview) convertview .findviewbyid(r.id.teamname); lbllistheader.settypeface(null, typeface.bold); lbllistheader.settext(_listdataheader.get(groupposition).getname()); return convertview; } @override public boolean hasstableids() { return false; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; }
}
recipe object:
public class recipe implements parentlistitem { private string mname; private list<ingredient> mingredients; public recipe(string name, list<ingredient> ingredients) { mname = name; mingredients = ingredients; } public string getname() { return mname; } @override public list<?> getchilditemlist() { return mingredients; } @override public boolean isinitiallyexpanded() { return false; } }
ingredient object
public class ingredient { private string mname; public boolean isselected() { return isselected; } public void setisselected(boolean isselected) { this.isselected = isselected; } public string getmname() { return mname; } public void setmname(string mname) { this.mname = mname; } private boolean isselected; public ingredient(string name) { mname = name; } public string getname() { return mname; }
}
Comments
Post a Comment