Can I add a click event to a text range?

I have a large text view that I am developing using SpannableStringBuilder. I want to be able to assign special click event handlers to certain text values. For example, if I click on a superscript character, I want it to lay out a toast with some information that references a superscript. So far I have found a link that helps make the type of regular expressions, such as emails and phone numbers, trigger the appropriate action. What I want to do is define the range and its style and assign it a click handler. I did not find anything built-in that supports this functionality, and so I ask someone who has a new understanding of how to do this. Thank.

+3
source share
2 answers

The only thing I can think of is to look at the Android source code for the class Linkifyand see how it is done.

+1
source

Take a look at the ClickableSpan extension. http://developer.android.com/reference/android/text/style/ClickableSpan.html

URLSpan, which is the range used for Linkify, is an example implementation of ClickableSpan. http://developer.android.com/reference/android/text/style/URLSpan.html

+1
source

Source: https://habr.com/ru/post/1726575/


All Articles