如果我的json文件是
[{name:xxxb fname:dddd tag1:F no:43434},{name:yyy fname:dfff tag1:T no:46464},{name:bbbb fname:nnnn tag1:F no:76676},{name:trtr fname:ghgh tag1:T no:5666}]
等等 我在eclipse android模拟器中获取listview中的所有显示但是如何更改我的json值'add'的颜色。 换句话说,如果json值加上:F,那么F应该在listview中以红色显示,否则如果add:T则T应该以红色显示。
答案 0 :(得分:-1)
请查看Count number of occurrences of a pattern in a file (even on same line) API:
JSONObject jsonObject;
String color, item;
String str = "<font color=\"%s\">%s</font>";
// handle the exception here
item = jsonObject.getString("add")
if("F".equalsIgnoreCase(item)){
color = "red";
}else if("T".equalsIgnoreCase(item)){
color = "green";
}else{
color = "blue";
}
// and inside your ArrayAdapter
itemTextView.setText(Html.fromHtml(String.format(Locale.US, str, color, item)));