I override SimpleAdapter:
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;
}
}
And the adapter is:
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});
There is an int parameter in each map called “readstate”, if the readstate == 1, then I want change the color of “Title” (TextView) to another color.
I know I should override getView(…) in my adapter, but I dont know how to do this. Will you please help me. Thank you in advance.
Override the Adapter’s
getItemViewType()to return two different layout flags, and overridegetViewTypeCount()to return the number of views. Then depending on flag, set the row layout ingetView():Here is a complete tutorial.