Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 737
thomaus Avatar asked Jan 08 '12 18:01

thomaus


1 Answers

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 :)

like image 190
kevinpelgrims Avatar answered Nov 18 '22 01:11

kevinpelgrims