我有一个简单的列表视图,我必须为每个具有不同颜色的替代行着色。
是否可以使用不同的颜色为listView着色。
答案 0 :(得分:2)
是。假设有ArrayAdapter,你必须做这样的事情:
public View getView(int position, View convertView, ViewGroup parent) {
...
if (position % 2 == 0) { // Even numbered row
// set a color as background for view
} else { // Odd numbered row
// set another color as background for view
}
...
}
答案 1 :(得分:0)
答案 2 :(得分:0)
是的,可能的,对于此用途getView()
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = (ViewHolder) convertView.getTag();
if (position == 0){
holder.layout.setBackgroundColor(Color.RED);
}
if (position == 1){
holder.layout.setBackgroundColor(Color.BLUE);
}
}
所以......