开发者

Links from Spanned text don't work in TexView

开发者 https://www.devze.com 2023-04-10 12:20 出处:网络
I have a Text开发者_如何学PythonView embedded in aRelativeLayout, embedded in a ScrollView, and I load a Spanned text object in it created from some HTML code.

I have a Text开发者_如何学PythonView 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);


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());
0

精彩评论

暂无评论...
验证码 换一张
取 消