我想根据变量更改我的 ListView 项目(使用 Async 类填充)的颜色。所以,我有这个
public class Search extends AsyncTask<Void, String, Void> {
boolean blue = false;
@Override
protected Void doInBackground(Void... params) {
Resources res = getResources();
List<String> Items = Arrays.asList(res.getStringArray(R.array.Items));
for (String it : Items) {
if (it.contains("blue")) { blue = true; } else { blue = false; }
publishProgress(it);
}
return null;
}
@SuppressWarnings("unchecked")
@Override
protected void onProgressUpdate(String... item) {
((ArrayAdapter<String>)getListAdapter()).add(item[0]);
// Change the color of the current item depending on "blue"
}
}
这可能吗?谢谢!