【发布时间】:2012-08-31 21:47:51
【问题描述】:
我想实现一个自定义的 SimpleCursorAdapter,它只在偶数行上显示背景颜色(在我的例子中是蓝色)。我的实现如下:
public class ColoredCursorAdapter extends SimpleCursorAdapter {
String backgroundColor;
public ColoredCursorAdapter(
Context context,
int layout,
String backgroundColor,
Cursor c,
String[] from,
int[] to,
int flags) {
super(
context,
layout,
c,
from,
to,
flags);
this.backgroundColor = backgroundColor;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
if(cursor.getPosition() % 2 == 0) {
view.setBackgroundColor(
Color.parseColor(backgroundColor));
}
}
}
一开始效果很好,但是当我反复向下和向上滚动列表时,所有行都变成蓝色。
提前致谢。
【问题讨论】:
标签: android list listview background simplecursoradapter