TextView to Hyperlink in Android

Linkfy class is used to generate hyperlinks in android so we must import it.
 Following steps are required to create a hyperlink.
1.We first create a SpannableString.
 Textview textview;   /*use  findViewById() to add a text view from XML*/
 SpannableString str = SpannableString.valueOf(/*charsequence  that you want work as hyperlink*/);
2.set it to a “blank” URL.
 str.setSpan(new URLSpan(“”), 0, entryValue.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);  /*blankURL*/
 textview.append(str) /*append string with textview*/
3.Then add a click listener to intercept the click.
  textview.tv.setOnClickListener(/*do anything u want, like:-snd msg to a prticular hyperlink number,make http connection,show something etc;
This looked like a normal hyperlink.But we do some more things in the listener when the link was clicked.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: