Skip to content Skip to sidebar Skip to footer

Android Expandable List View Get View Of Group From Child Onclick Listener

i have a expandable list view in my app, each group has a textview say T having dynamic value and each group has a single child within it. I want to refer to that T textview object

Solution 1:

// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        // TODO Auto-generated method stub
        Toast.makeText(
                getApplicationContext(),
                listDataHeader.get(groupPosition)
                        + " : "
                        + listDataChild.get(
                                listDataHeader.get(groupPosition)).get(
                                childPosition), Toast.LENGTH_SHORT)
                .show();
        returnfalse;
    }
});

I hope its useful for you.

Solution 2:

Use the getExpandableListAdapter() on the "parent" and define your custom classes accordingly. Then modify the values within the custom objects - the ExpandableListView will update automatically. E.g.:

@Override
public boolean onChildClick(ExpandableListView _parent, View _v,
        int _groupPosition, int _childPosition, long _id
) {
    // do required casts for your custom objects for groups and childs.// In my case, I'm using class "Group"
    Group group=(Group)parent.getExpandableListAdapter().getGroup(_groupPosition);
    // In my case, I'm using class "Child"
    Child item=(Child)optionsList.getExpandableListAdapter().getChild(_groupPosition, _childPosition);
    // In my custom Group class, I've defined a field that populates a different// TextView within the Group layout - so, getter/setter method for "selection" were defined.// The ExpandableListView will be updated automatically based on the adapter updates.group.setSelection(item.getName());
    returntrue;
}

Not exactly sure why this happens - it seems like the ExpandableAdapter is tracking changes to the model itself... I don't have time to check the details on this.. but it works.

Post a Comment for "Android Expandable List View Get View Of Group From Child Onclick Listener"