thomaus
thomaus

Reputation: 6258

Get expanded group view of an ExpandableListView using onGroupExpand

I'm using an ExpandableListView and I'm unsuccessfully trying to move an image when expanding a group (the image being part of the group view).

Here is my code :

my_list_view.setOnGroupExpandListener(new OnGroupExpandListener()
{
    @Override
    public void onGroupExpand(int groupPosition)
    {
        Toast.makeText(getBaseContext(), "Group " + my_list_view.getGroupId(groupPosition), Toast.LENGTH_SHORT).show();
    }
});

Basically my problem is : how can I access the expanded Group view, when the only variable I can use is groupPosition?

Any you-should-create-a-custom-adapter-like response won't be accepted. I already tried that and it doesn't work for my issue. What I need is to listen the onGroupExpand event.

Upvotes: 12

Views: 8906

Answers (1)

kevinpelgrims
kevinpelgrims

Reputation: 2156

What I eventually did is using the boolean isExpanded you get for free in getGroupView when you make a custom adapter. I was able to make things work the way I wanted with that, instead of doing it in the activity. If you save the context you get in the constructor, you can use that to get resources.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
  if (isExpanded) {
    mContext.getResources().getDrawable(R.drawable.arrow)
    doSomething();
  }
  else {
    doSomethingElse();
  }
}

That's a lot easier than my other answer (which was a bit buggy anyway), so forget about that one :)

Upvotes: 11

Related Questions