【发布时间】:2011-12-01 11:07:37
【问题描述】:
我正在尝试为可展开列表视图中的组设置动态背景。所以在我的 listviewAdapter 我有以下代码:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.elv_group, parent, false);
}
((LinearLayout) convertView.findViewById(R.id.elv_group_root_layout))
.setBackgroundColor(getBackgroundColor(groupPosition));
return convertView;
}
public int getBackgroundColor(int groupPosition) {
if (getGroup(groupPosition).getInput().size() != getGroup(groupPosition).getOutput().size()) {
return R.color.attention_row;
} else {
return R.color.normal_row;
}
}
如您所见,我尝试根据 getBackgroundColor 方法中的给定语句设置根布局背景颜色。
但我得到的只是一个总是灰色背景的组列表!谁能告诉我我在这里做错了什么? android列表生命周期或缓存机制似乎存在某种问题。 在可扩展列表视图中更改组的线性布局的颜色是否存在问题?还有其他突出特定群体的方法吗?
【问题讨论】:
-
你确定 getBackgroundColor 曾经返回 attention_row 颜色吗?
-
是的,getBackgroundColor 确实返回了正确的颜色(显示的不是灰色!)
标签: android android-layout expandablelistview