您好我有以下ArrayList元素从xml文件中获取值。之后,数据被送到一个显示它的简单适配器。我希望R.id.stock_mov的颜色根据值改变。如果是负 - >红色,如果它是正的那么是绿色。我无法找到如何做到这一点的方法
ArrayList<HashMap<String, String>> stackItems = new ArrayList<HashMap<String, String>> ();
// final HashMap<String, String> dspStack = new HashMap<String, String>();
NodeList stock = doc.getElementsByTagName("stock");
for (int i=0; i<stock.getLength(); i++){
HashMap<String, String> map = new HashMap<String, String>();
Node nodeCurr = stock.item(i);
Element currElmnt = (Element) nodeCurr;
map.put("name", parser.getValue(currElmnt, "name"));
map.put("val", parser.getValue(currElmnt, "val"));
map.put("mov", parser.getValue(currElmnt, "mov"));
stackItems.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, stackItems,
R.layout.stocks_def_item,
new String[] { "name", "val", "mov"}, new int[] {
R.id.stock_name,
if(stackItems.get(i)>0)
R.id.stock_val,
R.id.stock_mov,});
setListAdapter(adapter);
}
答案 0 :(得分:0)
您需要在adapter
的{{1}}方法中执行此操作。检查库存的价值,然后相应地设置相应的颜色:
getView()