【问题标题】:How to use getview() with a SimpleAdapter from AsyncTask?如何将 getview() 与 AsyncTask 中的 SimpleAdapter 一起使用?
【发布时间】:2014-06-23 09:55:39
【问题描述】:

我正在使用这样的 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;
    }
};

我的哈希图

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");

在这里,我需要为特定值设置条件是否退出我的哈希图中,如果该值退出,我需要更改该项目位置的颜色。我试过它不起作用。我怎样才能做到这一点?任何帮助都将不胜感激。

【问题讨论】:

标签: android listview simpleadapter


【解决方案1】:

在您的 getView 中尝试此代码

v.setBackgroundColor(youCondition? 0x9934B5E4: Color.TRANSPARENT);   

    return v;

【讨论】:

  • 我试过你的答案v.setBackgroundColor(details.containsValue("12")? 0x9934B5E4: Color.TRANSPARENT);所有项目都是透明的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 2017-11-17
  • 2012-03-18
  • 2013-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多