2

I have looked through many of the threads on this site to find the solution to my problem but none seem to work. At the moment I am able to create a hyperlink while displaying the website eg - Please go here - www.google.com (The www.google.com is hyperlinked). What I am trying to do is have the link as - Please go here (Here is the link). Below is the code i have tried but once I remove the link itself, the 'here' still highlights like a link but has no function.

Strings.xml:

<string name="goog">Please go <a href="www.google.com">here</a></string>

fragment_home.xml:

 <TextView
    android:id="@+id/npd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:autoLink="web"
    android:fontFamily="sans-serif-light"
    android:linksClickable="true"
    android:text="@string/npd"
    android:textColorLink="#FF0000"
    android:textSize="12dp" />

If i change 'here' for www.google.com within Strings.xml, the link takes me directly there. Has anyone been able to figure this problem out yet? Thanks in advance.

RunningWalks
  • 119
  • 2
  • 14

1 Answers1

4

Try this and let me know is it what you are looking for

TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
Badrul
  • 1,582
  • 4
  • 16
  • 27
  • Thank you for your help. Obviously due to it being within a fragment i had to use different code for the view call. Once this was changed it worked perfectly. Your a life saver :) – RunningWalks Jun 25 '14 at 09:06