Expandable ListView onGroupExpanded & onGroupCollapsed
guys i have 3 groups for my expandable listview, i try to change the color of each group respectively, when they're expanding and back to normal color when they're collapsing...
the problem i've been facing right now is that when i click the first group, it changes the color of the last group..., so i can say that they colors changed randomly not to the corresponding group.
here's the simple code that i use:
listView.setOnGroupClickListener(new OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int position, long id)
{
v.setBackgroundResource(R.drawable.group_bar_press);
Toast.makeText(getBaseContext(), "Group clicked", Toast.LENGTH_LONG).show();
return false;
}
});
w开发者_如何学编程ell, that's all i hope it'll be solved :)
i'm so sloppy :p
simply used Boolean isExpanded on my getView method, where i use to return my view,
and do it like this:
if(isExpanded){
convertView.setBackgroundResource(R.drawable.press);
}else{
convertView.setBackgroundResource(R.drawable.normal);
}
lol
You have to modify the getGroupView method in the ExpandableList Adapter with:
if (isExpanded) {
convertView.setBackgroundColor(0xFF0db6a3);
} else {
convertView.setBackgroundColor(0xFFFFFFFF);
}
return convertView;
And all together the result is like this:
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
if (isExpanded) {
convertView.setBackgroundColor(0xFF0db6a3);
} else {
convertView.setBackgroundColor(0xFFFFFFFF);
}
return convertView;
}
I was facing the same issue, so did this: Instead of changing the color of one group, change the color of all 3 at the same time, whatever color you want.
May not be good solution but worked for me.
精彩评论