Links from Spanned text don't work in TexView

496 views Asked by At

I have a TextView embedded in a RelativeLayout, embedded in a ScrollView, and I load a Spanned text object in it created from some HTML code. I have set the android:autoLink attribute of the TextView to true, and I have tested in another part of the application that I can click on links in the text and they will take me to the target website. The only difference is that this time the TextView is a child of a ScrollView. Does that screw up the android:autoLink process or am I really missing something here?

XML Code:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:padding="10dp" android:background="#FFF">
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/RLNewsItem">

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignParentLeft="true"
            android:id="@+id/TVText" android:textColor="#000"
            android:layout_below="@+id/TVTitle" android:linksClickable="true"
            android:autoLink="web|email|map"></TextView>
        </RelativeLayout>
    </ScrollView>

Java code:

Spanned newsText = Html.fromHtml(htmlsource, this, null);
text.setText(newsText);
1

There are 1 answers

1
Venky On BEST ANSWER

Try this Code in String.xml :

<string-array name="description">
 <item> <Data> <![CDATA[ Check this <u>Redirect to Next Activity</u> ]]></Data> </item>

Code in Java class:

     ArrayList<String> title_list = new ArrayList<String>();
     String[] description_Array = getResources().getStringArray(R.array.description);
     String categoryAndDesc = null;
     for(String cad : description_Array) {
        categoryAndDesc = cad;
        title_list.add(categoryAndDesc);
    }
    CharSequence sequence = Html.fromHtml(categoryAndDesc);
    seperator_view.setText(strBuilder);
    seperator_view.setMovementMethod(LinkMovementMethod.getInstance());