0

I'm facing a strange issue, that I could not fix with the solutions I found on related topics. (through StackOverflow or other sites)

It is summarized on that StackOverflow topic :

Display HTML Formatted String

So I am asking you. Why the heck is none of those solutions working in my project ?

I even tried to use WebView instead of my TextView ! Nada ! (html tags seem to be simply ignored)

This is my TextView :

<TextView android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="@+id/signupLinkText"
android:text="" android:gravity="center_horizontal"
android:clickable="true" android:layout_margin="5px"
android:layout_marginTop="10px" android:layout_marginBottom="10px"></TextView>

And the code I use to put my html code

Spanned spannnedSignupLink = Html.fromHtml(getString(R.string.lbl_not_yet_subscribed));
signupLinkText.setText(spannnedSignupLink, BufferType.SPANNABLE);

Then The html that must be interpreted in strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- ... -->
    <string name="lbl_not_yet_subscribed">To sign up to RESA Mobile, <strong>click here</strong> !</string>
</resources>

Thank you for the time you've spent in reading me,

Regards

Community
  • 1
  • 1
Codii
  • 873
  • 7
  • 18

2 Answers2

2

Post the html your attempting,

This works for me:

 <TextView
        android:id="@+id/message" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:padding="5dip" 
        android:textColor="#FFFFFF" />


  TextView textView = (TextView) findViewById(R.id.message);
  textView.setMovementMethod(LinkMovementMethod.getInstance());
  String message = "Blah blah blah <a href=\"http://google.com\">Google Link</a> blah blah blah.";
  textView.setText(Html.fromHtml(message));
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Thank you so much ! I'm so stupid, that is the double-quote escaping that saved my life! +1000 – Codii Jun 10 '11 at 12:42
  • For your information, to solve my specific problem, (My HTML string was in strings.xml) I just surrounded my html code with <![CDATA[]]> tag, and escaped the '"'. And the result is : `<![CDATA[To sign up to RESA Mobile, click here!]>` Not trickier than that! Thank you Blundell ;) ! Cheers – Codii Jun 10 '11 at 12:54
0

This should work:

TextView textView = findViewById(R.id.signupLinkText);
textView.setText(Html.fromHtml(...put the HTML here...));
Toni Toni Chopper
  • 1,833
  • 2
  • 20
  • 29