使用以下方法填充ListView:
list = (ListView) findViewById(R.id.historylist);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
String[] titles = new String[]{"transactionID","date","description","redeem","reward","status"};
try{
for(int i=0;i<rows.length();i++){
map = new HashMap<String, String>();
for(int n=0;n<allRows.getJSONArray(i).length();n++){
map.put(titles[n], allRows.getJSONArray(i).getString(n));
}
mylist.add(map);
}
mSchedule = new SimpleAdapter(
History.this,
mylist,
R.layout.history_row,
titles,
new int[] {R.id.textView0, R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5});
list.setAdapter(mSchedule);
for(int i=0; i<mylist.size(); i++)
if(((Map<String, String>) mSchedule.getItem(i)).get("status").equals("0"))
try{
// SET BACKGROUND COLOR OF ROW
}catch(Exception e){
Log.e("AAA Error getting ListView row", e.toString());
}
}catch(Exception e){
Log.e("Error Creating ListView", e.toString());
}
我想更改任何包含状态“0”的ListView行的背景颜色。
有什么想法吗?
新:这是更新的代码 - 更好(除了我必须手动切断JSONArray中的字符的部分.. eww ..)
private void showListView(JSONArray rows, JSONArray totals){
list = (ListView) findViewById(android.R.id.list);
ArrayList<String[]> rowValues = null;
String[] r = null;
try{
rowValues = new ArrayList<String[]>();
for (int i=0;i<rows.length();i++){
r = rows.get(i).toString().replaceAll("\\[\"", "").replaceAll("\"\\]", "").split("\",\"");
rowValues.add(r);
}
mba = new MyBaseAdapter(this, rowValues);
list.setAdapter(mba);
}catch(Exception e){
Log.e("showListView() ERROR", e.toString());
}
}
答案 0 :(得分:1)
我认为你不能。实现你所说的唯一方法是创建一个扩展BaseAdapter的新类,并在该类的getView()方法中更改视图的背景颜色