我正在为android开发一个闹钟应用程序,我想在主屏幕上显示闹钟列表。每一行都ListView
在 xml 文件中定义。我想为TextViews
一周中的每一天分开。例如,程序将检查 sqlite db。is = 1的值monday
,然后将其颜色更改TextView
为红色。我已经编写了这段代码,但这不起作用。怎么了?
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = db.fetchAllAlarms();
startManagingCursor(c);
String[] from = new String[] { db.KEY_TIME, db.KEY_NAME };
int[] to = new int[] { R.id.time, R.id.alarmName };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter alarms =
new SimpleCursorAdapter(this, R.layout.alarm_row, c, from, to);
alarms.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int dayOfWeekIndex = cursor.getColumnIndex("mon");
if (dayOfWeekIndex == columnIndex) {
int color = cursor.getInt(dayOfWeekIndex);
switch(color) {
case 0: ((TextView) view).setTextColor(Color.RED); break;
case 1: ((TextView) view).setTextColor(Color.GRAY); break;
}
return true;
}
return false;
}
});