Java ListView动态定制
我得到了这个方法setListView(),我使用它来用SQLite数据库中的数据填充ListView lv:Java ListView动态定制,java,android,sqlite,listview,android-listview,Java,Android,Sqlite,Listview,Android Listview,我得到了这个方法setListView(),我使用它来用SQLite数据库中的数据填充ListView lv: public void setListView (){ String[] columns= {DbHelper.C_ID, DbHelper.col1, DbHelper.col2, DbHelper.col3, DbHelper.col4,DbHelper.col5}; Cursor cursor = db.query(DbHelper.TABLE_NAME, col
public void setListView (){
String[] columns= {DbHelper.C_ID, DbHelper.col1, DbHelper.col2, DbHelper.col3, DbHelper.col4,DbHelper.col5};
Cursor cursor = db.query(DbHelper.TABLE_NAME, columns, null, null, null, null, "_id DESC");
String[] from= { DbHelper.col1, DbHelper.col2, DbHelper.col3, DbHelper.col4, DbHelper.col5};
int[] to = {R.id.tvCol1, R.id.tvCol2, R.id.tvCol3, R.id.tvCol4, R.id.tvCol5};
SimpleCursorAdapter adapter = new SimpleCursorAdapter (getApplicationContext(), R.layout.list_row, cursor, from, to);
lv.setAdapter(adapter);
}
有一个textView R.id.tvCol5,它是列表行(R.layout.list_行)的一部分。我想根据在SQLite数据库列DbHelper.col5中输入的内容动态更改R.id.tvCol5(setText、set background color等)的属性。
例如,如果该特定行的DbHelper.col5中的条目是字符串“RED”,我希望使该特定行中的textView R.id.tvCol5具有红色背景,并将文本设置为“RED”
有没有可能做到这一点,或者有没有其他方法可以达到同样的效果
谢谢大家。致以最诚挚的问候。您需要在适配器中执行此操作,换句话说,您必须制作一个自定义适配器,扩展游标适配器或baseadapter或类似的东西 然后,您只需检查字符串的值,并根据该值对其返回的视图执行某些操作(即,将背景设置为红色)