Reputation: 39
I have two TextViews in a ListView ,bind data by SimpleAdapter,I want to show different color in a single TextView,I use Html.fromHtml,but style can't work,so pls help..
simpleAdapter = new SimpleAdapter(NewsListActivity.this, list, R.layout.list_item, new String[] { "title", "source" }, new int[] { R.id.tvTitle, R.id.tvSource });
listview.setAdapter(simpleAdapter);
ArrayList<Map<String, Object>> list= new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", Html.fromHtml("<u>it's an another day.</u>"));
map.put("source", Html.fromHtml("<font color=#ffcc00>bbc news</font>"));
list.add(map);
Upvotes: 0
Views: 261
Reputation: 9336
As @FD suggested you need a custom ListView containing a TextView, then in that Text View you can have a sentence with different colors using the code below.
textView.setText(Html.fromHtml("<font color='red'>First line</font><br/><font color='blue'>Second line</font>"));
Upvotes: 0
Reputation: 12919
You'll have to implement a custom ListViewAdapter. In getView(), you can then instantiate your own row layout and set the text color.
Information on custom Adapters can be found e.g. here: http://www.vogella.com/tutorials/AndroidListView/article.html
Upvotes: 2