karla
karla

Reputation: 4606

How to get Group position from onChildClick()?

I have an ExpandableListView view and I've implemented OnChildClickListener, but I need to get the group of that child, more specifically - the text staying as a label of that group.

How can I do that?

  1. Should I implement OnGroupClickListener?

  2. Can somebody show me how to use getPackedPositionGroup() or any of the getPacked<somethingf>() methods to get to the text on the group element of expandable list view?

[Edit - addition]

the called is in Map class, which is something like this:

public class MapCommand extends Activity implements OnChildClickListener {
.....

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

    firstStepSwitcher(v, childPosition);

            ///HERE IS WHERE I WANT TO FIND THE GROUP!!!

        return true;
    }
}

The view itself is in the layout XML. I do not manage its display manually.

And it has separate class for adapter.

Upvotes: 1

Views: 3684

Answers (1)

karla
karla

Reputation: 4606

What I did wrong was that I used to take the adapter for that ExpandableListView like this:

in (public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id))

parent.getAdapter();

But after looking into detail in the specification I found that I should take it like this:

ExpandableListAdapter mAdapter = parent.getExandableListAdapter();

from there on I do not have problem to get my group by calling:

String groupName = (String) mAdapter.getGroup(groupPosition);

Upvotes: 4

Related Questions