android: Set link with <a href> in TextView
I finally got it working using the following code :
TextView tv1 = new TextView(this);
tv1.setLayoutParams(textOutLayoutParams);
tv1.setText(Html.fromHtml("<a href=\""+ l.getRightString() + "\">" + l.getLeftString() + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod (LinkMovementMethod.getInstance());
dialogLayout.addView(tv1);
l.getRightString() - contains a url like http:\www.google.com l.getLeftString() - contains text for the url like "Go to Google"
RESULTS : Text "Go to Google" on my dialog with blue color and underlined, and on clicking it the browser opens up and shwows the respective page. On returning/Exiting the browser it again comes to the app from the state where it had left.
Hope this helps.
Save your html in a string
<string name="link"><a href="http://www.google.com">Google</a></string>
Set textview ID to to
textViewLinkable
In main activity use following code:
((TextView) findViewById(R.id.textViewLinkable)).setMovementMethod(LinkMovementMethod.getInstance());
((TextView) findViewById(R.id.textViewLinkable)).setText(Html.fromHtml(getResources().getString(R.string.link)));