I try to swap expandablelistview group background image when it is collapse or expand. But the background image was not correctly swap. For example when I expand the first group, background of second or third group get swapped.
I am using RelativeLayout (group layout) and SimpleExpandableListAdapter (adapter). Here is what I did:
// Create 2 drawable background. One for collapse and one for expand
private Drawable collapseBG, expandBG;
private ExpandableListView myView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
collapseBG = getResources().getDrawable(R.drawable.box_bg_header_collapse);
expandBG = getResources().getDrawable(R.drawable.box_bg_header_expand);
myView = (ExpandableListView) findViewById(R.id.myView);
}
myView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
public void onGroupCollapse(int groupPosition_c) {
myView.getChildAt(groupPosition_c).setBackgroundDrawable(collapseBG);
}
});
myView.setOnGroupExpandListener (new ExpandableListView.OnGroupExpandListener() {
public void onGroupExpand(int groupPosition_e) {
myView.getChildAt(groupPosition_e).setBackgroundDrawable(expandBG);
}
});
Is anyone know how to make this works?