这个我的代码:
for(int i = 0;i< cursor.getCount(); i++){
String notes = Name[i];
sb = new SpannableStringBuilder(notes);
Pattern p = Pattern.compile("A", Pattern.CASE_INSENSITIVE);
Pattern p2 = Pattern.compile("c", Pattern.CASE_INSENSITIVE);
m = p.matcher(notes);
m2 = p2.matcher(notes);
while (m.find()){
sb.setSpan(new ForegroundColorSpan(Color.rgb(255, 0, 0)), m.start(), m.end(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
while (m2.find()){
sb.setSpan(new ForegroundColorSpan(Color.rgb(255, 255, 0)), m2.start(), m2.end(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
我的问题:如何将(sb)放入hashmap,我希望listview中的内容具有我设置的颜色。在上面的范围(字符串注释)中设置颜色
txtView.setText(sb);
map = new HashMap<String, String>();
map.put("x1",ID[i]);
map.put("x2",Name[i]);
myList.add(map);
}
SimpleAdapter Adapter = new SimpleAdapter(this, myList, R.layout.mycustom_list,
new String[] {"x1","x2"},
new int[]{R.id.textID, R.id.textName});