Cursor
の情報をListView
に表示しようとしていますが、各行にImageView
とTextView
が含まれています。私はCustomCursorAdapter
をCursorAdapter
に広げて、bindView
で私はカーソルからデータを評価し、それに基づいてビューのイメージとテキストを設定します。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
}
}
}
これを後で試しますが、1つのコメント:コンストラクタでこれらの 'cursor.getColumnIndexOrThrow(DbAdapter.MONITORS_COLUMN_MONITOR_NAME);コールを実行する必要があります。あなたは 'Log.e'例外についてどうですか? –