Example usage for android.text SpannableString nextSpanTransition

List of usage examples for android.text SpannableString nextSpanTransition

Introduction

In this page you can find the example usage for android.text SpannableString nextSpanTransition.

Prototype

public int nextSpanTransition(int start, int limit, Class type);

Source Link

Document

Return the first offset greater than start where a markup object of class type begins or ends, or limit if there are no starts or ends greater than start but less than limit.

Usage

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static void linkify(TextView tv) {
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence t = tv.getText();
    if (!(t instanceof SpannableString)) {
        return;//from w ww .  jav  a  2 s .  c o m
    }
    SpannableString text = (SpannableString) t;

    int len = text.length();

    int next;
    for (int i = 0; i < text.length(); i = next) {
        next = text.nextSpanTransition(i, len, URLSpan.class);
        URLSpan[] old = text.getSpans(i, next, URLSpan.class);
        for (int j = old.length - 1; j >= 0; j--) {
            text.removeSpan(old[j]);

            UrlSpan2 span2 = new UrlSpan2(old[j].getURL());
            text.setSpan(span2, i, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

}