【发布时间】:2011-08-06 11:27:32
【问题描述】:
嘿,是否可以更改 ExpandableListView 中指定行的背景?我想要的是:第一排蓝色,第二排红色,第三排蓝色,第四排红色.....谢谢
【问题讨论】:
嘿,是否可以更改 ExpandableListView 中指定行的背景?我想要的是:第一排蓝色,第二排红色,第三排蓝色,第四排红色.....谢谢
【问题讨论】:
是的,这是可能的,您必须为展开式列表视图使用自定义适配器。
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
//......
//...... Your code for row view
//.....
//Now write here code for set colors for rows
if(childPosition % 2 == 0) {
convertView.setBackgroundColor("#0000FF"); // use this when you want to use hexa value of colors
} else {
convertView.setBackgroundColor("#FF0000"); // use this when you want to use hexa value of colors
}
//setBackgroundResource(android.R.color.transparent); // use this for predefined colors at place of setBackground
return convertView;
}
阅读this 文章,此处还提供示例和源代码。
【讨论】:
您可能想查看this thread: Android ExpandableListView。
有一个 working sample 具有您想要的功能(根据它们保存的数据为行着色)。
【讨论】:
当然。您只需在创建或重新创建视图时手动设置视图的背景。在方法中的适配器中执行此操作
getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
基于组和子位置
【讨论】: