【发布时间】:2011-05-09 03:30:34
【问题描述】:
我正在使用这段代码更改覆盖 onListItemClick 的每一行的背景颜色
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// First time touching the item
if(mLastPosition==-1) {
mLastPosition = position;
} else {
mLocalBG.remove(String.valueOf(mLastId));
v = l.getChildAt(mLastPosition);
v.setBackgroundColor(Color.WHITE);
mLastPosition = position;
}
mLocalBG.add(String.valueOf(id));
/* The issue: v is returning null right here, but only when touch a row that was below the first ones displayed, rows that needed to be scrolled down */
v = l.getChildAt(position);
v.setBackgroundColor(Color.LTGRAY);
}
如前所述,直到我向下滚动到下一行,它才能完美运行,之后 View v 每次都返回 null。为什么会这样?
提前致谢
【问题讨论】:
标签: android listview android-layout background-color