Reputation: 261
HI I have a question I can't seem to figure out. I am trying to add HTML to a textView that is a column in a ListView. I have a 3 coulmn row for a ListView.
My code to add the html to a textView is:
TextView mTextSample = new TextView(this);
String text = "Visit my <a href='http://www.newblog.com'>blog</a>";
mTextSample.setText(Html.fromHtml(text));
Then I have a HashMap in which I add mTextSample.getText() too:
HashMap Object, Object map = new HashMap Object, Object();
map.put("c1", "STATUTE");
map.put("c0", "");
map.put("c2", mTextSample.getText());
mylist.add(map);
Then this row is added to my ListView (R.id.CELL2 should have the html in it):
final ListView listnew = (ListView) findViewById(R.id.lvdata);
SimpleAdapter mSchedulenew = new SimpleAdapter(this, (List<? extends Map<String, ?>>) mylist, R.layout.row,
new String[] {"c1","c0","c2"}, new int[] {R.id.CELL1,R.id.CELLBlank, R.id.CELL2});
listnew.setAdapter(mSchedulenew);
But when run only the "Visit my blog" is displayed (which is correct but no link is generated). It seems like the html is being filter out when I add this row to the listView.
Upvotes: 0
Views: 1354
Reputation: 10039
This should do it -
TextView mTextSample = new TextView(this);
mTextSample.setMovementMethod(LinkMovementMethod.getInstance());
String text = "Visit my <a href='http://www.newblog.com'>blog</a>";
mTextSample.setText(Html.fromHtml(text));
Upvotes: 1