java - Clickable words inside of TextView Android -


this question has answer here:

i have textview contains hashtags ex. #first #second #third. question how can detect hashtag clicked can perform action - eg. make toast of word. possible using textview widget? should use other widget istead?

update

i found solution using this example. hope others in future!

you can use spannable string achieve this:

spannablestring ss = new spannablestring("your string"); string[] words = ss.split(" "); for(final string word : words){    if(word.startswith("#")){      clickablespan clickablespan = new clickablespan() {     @override     public void onclick(view textview) {         //use word here make decision      }     };     ss.setspan(clickablespan, ss.indexof(word), ss.indexof(word) + word.length(), spanned.span_exclusive_exclusive);   } }   textview textview = (textview) findviewbyid(r.id.hello); textview.settext(ss); textview.setmovementmethod(linkmovementmethod.getinstance()); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -