开发者

How to get Group position from onChildClick()?

开发者 https://www.devze.com 2023-01-30 07:21 出处:网络
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.

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 WA开发者_StackOverflowNT 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号