https://medium.com/viithiisys/android-multiple-click-actions-on-single-textview-c5fec71b6e25
[code language=”java”]
private static void singleTextView(TextView textView, final String userName, String status, final String songName) {
SpannableStringBuilder spanText = new SpannableStringBuilder();
spanText.append(userName);
spanText.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
// On Click Action
}
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.setColor(textPaint.linkColor); // you can use custom color
textPaint.setUnderlineText(false); // this remove the underline
}
}, spanText.length() – userName.length(), spanText.length(), 0);
spanText.append(status);
spanText.append(songName);
spanText.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
// On Click Action
}
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.setColor(textPaint.linkColor); // you can use custom color
textPaint.setUnderlineText(false); // this remove the underline
}
},spanText.length() – songName.length(), spanText.length(), 0);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(spanText, TextView.BufferType.SPANNABLE);
}
[/code]