set Html to TextView - Android android.widget

Android examples for android.widget:TextView

Description

set Html to TextView

Demo Code

import android.app.Activity;
import android.net.Uri;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static void setHtml(Activity activity, View parent,
            int elementId, int resId) {
        TextView view = (TextView) parent.findViewById(elementId);
        view.setText(Html.fromHtml(activity.getString(resId)));
    }//ww w. jav  a 2  s  .c o  m
    public static void setHtml(TextView view, String html) {
        view.setVisibility(View.GONE);

        if (html != null && html.length() != 0) {
            view.setText(Html.fromHtml(html));
            view.setVisibility(View.VISIBLE);
        }
    }

}

Related Tutorials