我从数据库中检索我的游泳成绩。我想根据他的值改变一个字段的背景颜色。例如,如果我游泳 4 圈,我想要彩色背景。我尝试正确设置背景但文本消失的代码。
String[] columns = new String[] { "swimm_pos", "swimm_date","swimm_lap", "swimm_stroke", "swimm_time", "swimm_media", "swimm_efficiency", "swimm_note" };
int[] to = new int[] { R.id.row_counter, R.id.swimm_date, R.id.swimm_lap, R.id.swimm_stroke, R.id.swimm_time, R.id.swimm_medialap, R.id.swimm_efficiency, R.id.swimm_note};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this,
R.layout.contacto_list_item,
cursor,
columns,
to);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.swimm_lap)
{
int color = cursor.getInt(columnIndex);
String s = String.valueOf(color);
if (s.equals("4")) {
TextView tv = (TextView)view;
tv.setBackgroundColor(0xFF558866);}
return true;
}
return false;}
});
并且也是可能的,当 lap 等于 4 时设置另一个字段的背景颜色,例如在我的代码中:R.id.swimm_pos? 谢谢你。