我使用SimpleAdapter生成ListView,如下所示:
adapter = new SimpleAdapter(TodayActivity.this, detailslist,
R.layout.singlerow, new String[] {"name","cname","cid","pid"},
new int[] { R.id.textView2,R.id.textView3,R.id.clid,R.id.projectid}){
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if(details.containsValue("12")){
//here if that value exits in hashmap
//I need to change a colour for that item position.
}
return v;
}
};
MyHashmap
HashMap<String, String> details = new HashMap<String, String>();
// adding each child node to HashMap key => value
details.put("name", "Project Name: "+Name);
details.put("cname", client_name);
details.put("cid", client_id);
details.put("pid", project_id);
details.put("flag", "False");
这里我需要为特定值设置条件是否在我的hashmap中退出,如果该值退出,我需要更改该项目位置的颜色。我试过它没用。我怎样才能做到这一点?任何帮助都会很明显。
答案 0 :(得分:0)
在getView中尝试此代码
v.setBackgroundColor(youCondition? 0x9934B5E4: Color.TRANSPARENT);
return v;