0
在我的應用程序中,我從SQlite數據庫中拖出3個字符串來填充ListView。在Listrow中,我必須使用TextViews和ImageView。SimpleCursorAdapter.ViewBinder - 對每行應用不同(ListFragment)
這兩個TextView目前正確填充(每行不同的文本)。但是,這不是我使用ViewBinder設置的ImageView。即,每行中的圖像都獲得相同的顏色。我怎樣才能解決這個問題?我需要擴展SimpleCursorAdapter嗎?
String[] from = {DbHelper.NAME, DbHelper.COMMENT, DbHelper.COLOR};
String[] column = {DbHelper.C_ID, DbHelper.NAME, DbHelper.COMMENT, DbHelper.COLOR};
int[] to = {R.id.listitem_title, R.id.listitem_summary, R.id.listitem_color};
Cursor cursor = db.query(DbHelper.TABLE_NAME, column, null, null, null, null, null);
this.adapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_set, cursor, from, to);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.listitem_color) {
cursor.moveToFirst();
String color = "#ffffff";
while (cursor.moveToNext()) {
color = cursor.getString(cursor.getColumnIndex(DbHelper.COLOR));
}
((ImageView) view).setBackgroundColor(Color.parseColor(color));
return true;
}
return false;
}
});
setListAdapter(adapter);
優秀(也不得不刪除cursor.moveToFirst)感謝的人! – Jakob
@Jakob是的,「光標」已經定位指向正確的行,您只需要從中檢索數據。 – Luksprog