Search code examples
androidhtmltagstextviewclickable

<a href ="www.xyz.com">XYZ </a> Not working in android


i have searched on Stack overflow and followed the solution but still not getting what i want. i am receiving String from server like this

  <p><a href="http://www.arenafootball.com/sports/a-footbl/aflsrk/mtt/micheaux_robinson_841978.html"><span style="font-size: small;"><strong>AFL Stats</strong></span></a></p>

and now i am trying to display it in TextView in android usingtv.setText(Html.fromHtml(""))

Code:

TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(Html.fromHtml("myrecivedString"));
tv.setMovementMethod(LinkMovementMethod.getInstance());

XML:

 <TextView
   android:id="@+id/tv"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:autoLink="all"
   android:linksClickable="true" />

Expected output:

AFL Stats

its clickable but in my android app the output is not clickable .what's wrong with my code ?


Solution

  • tv.setText( Html.fromHtml("your string"));
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    

    and don't use android:autoLink="all" on TextView in XML. then try it should work.....