我重写SimpleAdapter:Android:我如何更改ListView的一个项目的颜色?
class NoticelistAdapter extends SimpleAdapter
{
public NoticelistAdapter(Context context,
List<? extends Map<String, ?>> data, int resource,
String[] from, int[] to)
{
super(context, data, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Map<String,Object> map= list.get(position);
int readState = (Integer) map.get("ReadState");
if (readState == 1)
{
// do something to change the color of title
}
return convertView;
}
}
和适配器是:
adapter = new NoticelistAdapter(NoticelistActivity.this, list, R.layout.row_noticelist,
new String[] { "Title", "RealName","Date"},
new int[] { R.id.noticetitle, R.id.noticerealname,R.id.noticedate});
有一个在每个称为 “READSTATE” 图int参数,如果READSTATE == 1,那么我想改变“标题”(TextView)的颜色为另一种颜色。 我知道我应该重写getView(...)在我的适配器,但我不知道如何做到这一点。你能帮我吗?先谢谢你。
首先看到这个:http://www.vogella.com/articles/AndroidListView/article.html –