Search code examples
androidappceleratorclickablespan

How to make a part of a text clickable (appcelerator, android)


I am trying to achieve a functionality where user can click a part of a text such as the username or a hashtag in a string which is used by most social apps. There doesn't seem to be a way as of now. Any help will be most appreciated. Ti SDK 5.2.2 Android


Solution

  • Try to use an AttributedString. It allows you to display "html" like text. There is an easy to use module: https://github.com/FokkeZB/ti-html2as where you can set HTML text and it will convert it to an AttributedString.

    So you would use a regular expression to convert you clickable elements (e.g. #element -> <a href="#element">#element</a>) and check for the click response