3

I have this layout:

<TextView
    android:clickable="true"
    android:focusable="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView" />

And this code to implement and set my customized URLSpan as the textView text

val urlSpan=object:URLSpan("http://10.0.2.2/feed.xml") {
    override fun onClick(widget: View?) {
        longToast("link was clicked!")
    }
}
val spannableString=SpannableString("this is a spannable link")
spannableString.setSpan(urlSpan, 10, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
textView.text = spannableString

But the onClick event of my customized URLSpan never triggers :( I've searched and nothing seems to work.

I've read this: android custom URLSpan not working and other threads but it was in vain.

Avijit Karmakar
  • 8,890
  • 6
  • 44
  • 59
Raymond Arteaga
  • 4,355
  • 19
  • 35
  • https://stackoverflow.com/questions/15699535/android-span-click-event – Sivakumar S Feb 03 '18 at 01:29
  • 1
    Thanks a lot! I've been passing over LinkMovementMethod for hours without noticing it was the key! Thnaks for the help :) – Raymond Arteaga Feb 03 '18 at 02:17
  • I'm not really shure if I should delete this post... other posts I've read are "overflowed" by superfluous information. I spent more than 3 hours reading threads and googling my question, and simply ignoring the answer, just because I though the answers where responding questions that hasn't anything to do whith mine. The code I posted is "raw" and clear... it should work... but it doesn't, just becouse a key piece (LinkMovementMethod stuff) is missing. That's the answer to the question. (PD: Please excuse my english, I'm out of training) – Raymond Arteaga Feb 04 '18 at 00:08
  • the question linked in the top as relevant to this one, has nothing to do with it actually :D – aya salama Mar 05 '19 at 08:46

0 Answers0