A.S
A.S

Reputation: 21

How to make links in textview clickable

How to make links clickable in text view. This is the problem

(1). view.setMovementMethod(LinkMovementMethod.getInstance()); this works only when textview contains link(anchor tag/href) like this:

<a href="http link">Go to Google</a>

it does'nt work when textview contains link like this: http link

(2). While android:autoLink="web" this works only when textview contains link like this: http link it does'nt work when textview contains link like this:

<a href="httplink">Go to Google</a>

What to do when textview contains both types of link. Please help.

Upvotes: 0

Views: 1094

Answers (3)

Try This

     String mobile = "12345678";    

Set this text with link and click listener

     SpannableString mobile_underline = new SpannableString(mobile);
     mobile_underline.setSpan(new UnderlineSpan(), 0, mobile.length(), 0);
     textviewID.setOnClickListener(new PhoneNumberClickListener());//Implement custom listener to write respective code of click listener 

Upvotes: 0

Haresh Ramani
Haresh Ramani

Reputation: 390

try this

<TextView
                android:id="@+id/message_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="http://www.google.com"
                android:gravity="center_vertical"
                android:textColor="@color/white"
                android:textColorLink="@color/white"
                android:linksClickable="true"
                android:autoLink="web"
                android:textStyle="normal"
                android:textSize="15sp" />

Upvotes: 3

Zeeshan Shabbir
Zeeshan Shabbir

Reputation: 7104

Try this

textView.setOnClickListener(new View.OnClickListener());

in xml:

android:clickable="true"

or you can use String

 htmltext=Html.fromHtml(htmltext)

then set this htmltext to textview

textview.setText(htmltext)

Upvotes: 1

Related Questions