0

Im having an android app that takes info from RSS (in pure html form, including p tags, and a href tags).

Here's the code that creates the alertdialog:

Builder alertDialog=new AlertDialog.Builder(Activity.this);
alertDialog.setMessage(Html.fromHtml(rss.getDesc()));
alertDialog.setNegativeButton("אישור", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
    }
});
alertDialog.show();

Now, as I have already mentioned, the rss.getDesc()-method brings full html code.

As you can see, I have managed to handle the html, but the hyper links don't work... Here's an example of html: (ignore the language)

<p dir="rtl" align="right">כידוע לכם, עומר וייסבלום זכה בתחרות &quot;המורה של המדינה&quot; ובימים אלו מסייר בבתי ספר בארה&quot;ב במשלחת ישראלית שיצאה במסגרת הזכייה.</p>
<p dir="rtl" align="right"> מצ&quot;ב לינק לכתבה על עומר בעיתון בי&quot;ס תיכון אמריקאי באזור וושינגטון בארה&quot;ב (Walt Whitman High School).</p>
<p><a href="http://www.blich.co.il/node/16346">הצג את ההמשך</a></p>

I would be glad if you can tell me what I am missing.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
RE6
  • 2,684
  • 4
  • 31
  • 57

1 Answers1

1

For this purpose, there is the Linkify-class. As the docs read:

Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links. [...]

Since you want to enable links in a Dialog, you'll want to use a Spannable for your text and pass it to Linkifys addLinks()-method.

An example (and similar question) can be found here: How can I get clickable hyperlinks in AlertDialog from a string resource?

Community
  • 1
  • 1
Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111