Apr 29, 2013

Display HTML String with link on TextView

Example to display HTML String with link on TextView:

package com.example.androidhtmltextview;

import android.os.Bundle;
import android.app.Activity;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

public class MainActivity extends Activity {
 
 String htmlString = "<i>Welcome to<i> <b><a href='http://android-coding.blogspot.com'>Android Coding</a></b>";

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  TextView htmlTextView = new TextView(this);
  setContentView(htmlTextView);
  
  htmlTextView.setText(Html.fromHtml(htmlString));
  htmlTextView.setMovementMethod(LinkMovementMethod.getInstance());
  
 }

}


Display HTML String with link on TextView
Display HTML String with link on TextView


No comments:

Post a Comment

Infolinks In Text Ads