I am trying to recognise hashtags in my TextView and make them clickable such that I can take the user to another View when they click on the Hashtag.
I managed to identify Hashtags in the TextView using Pattern Matching and they appear colored in Runtime. However, I need to make the Hashtag clickable.
Here's my Code:
SpannableString hashText = new SpannableString("I just watched #StarWars and it was incredible. It's a #MustWatch #StarWars");
Matcher matcher = Pattern.compile("#([A-Za-z0-9_-]+)").matcher(hashText);
while (matcher.find())
{
hashText.setSpan(new ForegroundColorSpan(Color.parseColor("#000763")), matcher.start(), matcher.end(), 0);
String tag = matcher.group(0);
}
holder.caption.setText(hashText);
//I need to set an OnClick listener to all the Hashtags recognised
Using the same solution above, how can I add onclick listeners to every hashtag?