我尝试在折叠或展开时交换可扩展列表视图组背景图像。但是背景图像没有正确交换。例如,当我展开第一组时,第二组或第三组的背景会被交换。
我正在使用RelativeLayout(组布局)和SimpleExpandableListAdapter(适配器)。这是我所做的:
// 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);
}
});
有谁知道如何使这个工作?