我正在使用游标适配器填充ListView,就像描述HERE:
一样DatabaseHelper databaseHelper = new DatabaseHelper(getActivity());
Cursor cursor = databaseHelper.getPeople();
String[] fromColumns = {"_id","firstname","lastname","email"};
int[] toViews = {R.id.count, R.id.firstname, R.id.lastname, R.id.email};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.person_name_and_email, cursor, fromColumns, toViews, 0);
ListView listView = getListView();
listView.setAdapter(adapter);
我的数据库表中还有另一个名为“status”的列,即该人是“朋友”,“家人”,“商业伙伴”等。
我将使用此列的内容来确定人物行的颜色;如果这个人是朋友,那行将是绿色的,如果这个人是家人,那行将是蓝色等等。
因此,我不希望“状态”数据作为列显示在ListView中,但我需要为每个迭代的行提供它。
有办法做到这一点吗?
谢谢!
答案 0 :(得分:1)
尝试覆盖getView()方法
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, layout, cursor, fromColumns, toViews, 0);
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
cursor.moveToPosition(position);
String s = cursor.getString(cursor.getColumnIndex(“status"));
final View row = super.getView(position, convertView, parent);
if (s.equalsIgnoreCase(“friend"))
row.setBackgroundColor();
return row;
}
};