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. |
Saturday, 8 December 2012
TextView to Hyperlink in Android
Labels:
android
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment