我正在尝试从 aCursor
中显示信息 a ListView
,每一行都包含 aImageView
和 a TextView
。我有一个CustomCursorAdapter
扩展CursorAdapter
,在bindView
我评估来自光标的数据并基于该设置视图图像和文本。
当我运行应用程序时,ListView
会显示正确的行数,但它们是空的。我知道我在覆盖 bindView 时错过了一些东西,但我不确定是什么。
任何帮助将不胜感激。
private class CustomCursorAdapter extends CursorAdapter {
public CustomCursorAdapter() {
super(Lmw.this, monitorsCursor);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
return layoutInflater.inflate(R.layout.row, null);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
try {
int monitorNameIndex = cursor.getColumnIndexOrThrow(DbAdapter.MONITORS_COLUMN_MONITOR_NAME);
int resultTotalResponseTimeIndex = cursor.getColumnIndexOrThrow(DbAdapter.RESULTS_COLUMN_TOTAL_RESPONSE_TIME);
String monitorName = cursor.getString(monitorNameIndex);
int warningThreshold = cursor.getInt(resultTotalResponseTimeIndex);
String lbl = monitorName + "\n" + Integer.toString(warningThreshold) + " ms";
TextView label = (TextView) view.findViewById(R.id.label);
label.setText(lbl);
ImageView icon = (ImageView)view.findViewById(R.id.icon);
if(warningThreshold < 1000) {
icon.setImageResource(R.drawable.ok);
} else {
icon.setImageResource(R.drawable.alarm);
}
} catch (IllegalArgumentException e) {
// TODO: handle exception
}
}
}