【发布时间】:2013-12-22 10:21:43
【问题描述】:
我有一个 ListView,其中包含自定义 row_layout.xml,其中包含 3 个 TextView。
要在列表视图中显示数据,我使用 LoaderManager
我想根据其中一项的值将所有 3 个 TextViews 背景颜色更改为红色/绿色/橙色。
为此,我在我的适配器 (SimpleCursorAdapter) 中覆盖了 setViewValue
dataAdapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int coloumIndex)
{
if (coloumIndex == cursor.getColumnIndex(SQLdataHelper.INVITE_STATUS))
{
TextView tv = (TextView) view.findViewById(R.id.invite_Status);
InviteStatus status = InviteStatus.valueOf(cursor.getString(cursor.getColumnIndex(SQLdataHelper.INVITE_STATUS)));
switch(status)
{
case atProgress:
{
tv.setTextColor(Color.parseColor("#ffa500"));
break;
}
case Completed:
{
//TextView tv2 = (TextView) view.findViewById(R.id.Invite_RequestedDate);
//TextView tv3 = (TextView) view.findViewById(R.id.invite_Name);
tv.setTextColor(Color.GREEN);
//tv2.setTextColor(Color.GREEN);
//tv3.setTextColor(Color.GREEN);
break;
}
case Received:
{
tv.setTextColor(Color.RED);
break;
}
}
return true;
}
return false;
}
});
此代码正在运行。但它只会更改其中一项..
在 switch 案例中,我尝试获取其他 2 个项目的 TextView,但我得到 NullPointerException
如何为列表中的其他 2 个项目着色?
【问题讨论】:
标签: android listview android-loadermanager