【发布时间】:2014-05-04 17:44:16
【问题描述】:
我已尝试更改 ListView 中特定项目的背景颜色。
首先,从数据库中捕获它:
ListAdapter adapter = new ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, db.getAllApps());
final ListView list = (ListView) findViewById(R.id.ListViewApps);
list.setAdapter(adapter);
然后我会将所有应用设置为不同的颜色,如果它们有标签激活
// if app is activated in db --> set another colour in ListView
private void setAppCheck(ListView list) {
List<String> apps = db.getAllApps();
for (int i = 0; i < list.getCount(); i++) {
if (db.appActivated(apps.get(i)).equals("activated")) {
list.setBackgroundColor(0xffaaaaaa); // it changes ALL items...
} else {
// do nothing
}
}
}
还有一个问题,list.setItemChecked(i, true) 我可以用特定位置更改它,但是如何更改ListView 中特定项目的背景颜色?
希望你能帮助我。
【问题讨论】:
-
使用
Custom Adapter并在getView方法中更改。
标签: android listview background-color listviewitem setbackground