您好我使用此代码在用户点击组时更改组的背景,并且组是折叠
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
if (!parent.isGroupExpanded(groupPosition)) {
v.setBackgroundColor(Color.parseColor("#ff9600"));
} else {
v.setBackgroundColor(Color.parseColor("#4fc1e9"));
}
if (parent.isGroupExpanded(groupPosition)) {
Toast.makeText(AdieActivity.this,String.valueOf( groupPosition), Toast.LENGTH_SHORT).show();
}
return false;
}
});
当用户点击并分组操作时,背景颜色会改变,但问题是,某些组未打开但背景也发生了变化
答案 0 :(得分:2)
重写的方法包含在我的自定义ExpandableListAdapter中。
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View view, ViewGroup parent)
{
LinearLayout bevGroup = (LinearLayout) view.findViewById(R.id.myid);
if(isExpanded)
{
bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgGroupBlack));
}
else
{
bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgTransparent));
}
}