我使用以下内容填充 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());
}
}