android - ExpandableListView ParentPosition not getting -
hi have searched lot on topic still unable solve this.i pretty new in android.i not getting position of parent in expandablelistview,i getting value of childposition not groupposition.
catlist = (expandablelistview) findviewbyid(r.id.category_list); final expandablelistadapter explistadapter = new expandablelistadapter( catergoryactivity.this, grouplist, expandablecategories); catlist.setadapter(explistadapter); catlist.setonchildclicklistener(new onchildclicklistener() { @override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { intent nextact = new intent(catergoryactivity.this, mobileactivity.class); string childposition = explistadapter.getchild(groupposition, childposition); system.out.println("childposition------------------------>>>>>>>>>>>>"+childposition); nextact.putextra("locid", locid); nextact.putextra("childpos", childlist.get(childposition)); nextact.putextra("grouppos", gruopposition); startactivity(nextact); return false; } });
according api refference description of onchildclick, have position of parent group.
public abstract boolean onchildclick (expandablelistview parent, view v, int groupposition, int childposition, long id) added in api level 1
callback method invoked when child in expandable list has been clicked.
parameters
- parent - expandablelistview click happened
- v -the view within expandable list/listview clicked
- groupposition - group position contains child clicked
- childposition - child position within group
- id - row id of child clicked
returns true if click handled
edited: there 2 positions in onchildclick need - parent , child. parent defines position of group, child defines position within group. adapter.getchild(grouppos, childpos) returns object related specified child item.
catlist.setonchildclicklistener(new onchildclicklistener() { @override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { system.out.println("childposition: " + childposition); system.out.println("groupposition: " + groupposition); // if need related data object itemdata = explistadapter.getchild(groupposition, childposition); } });
if need itemdata
value, should implement getchild() method in adapter.
Comments
Post a Comment