Search code examples
androidjsonhyperlinktextviewhref

How can I keep the links from a JSON in a TextView?


I'm collecting information from a JSON website and displaying it in my Android app as a TextView. The information is taken from a standard MySQL database and stripped of tags (with php).

What I want to do is keep the links in the texts. E.g. "For more information, click here", here is not a click-able link.

I tried keeping the " < a > " tags when stripping but that didn't get the desired effect in the app either.

Any suggestion of where to look next would be great...


Solution

  • Add in TextView

     android:autoLink="all"
    

    and add this line to your textview

    t3.setText(
            Html.fromHtml(
                "<b>text3:</b>  Text with a " +
                "<a href=\"http://www.google.com\">link</a> " +
                "created in the Java source code using HTML."));
        t3.setMovementMethod(LinkMovementMethod.getInstance());
    

    visit here for more .