I have implemented multiple clickable spans in a TextView. My intention is to remove that paticular span which has been clicked. I am catching the onClick event of the span but it returns the whole textview. How do i isolate the span which was clicked and remove it ?
Asked
Active
Viewed 1,491 times
1 Answers
2
Maybe this will help you:
String myText = "textA";
spannableStringBuilder = new SpannableStringBuilder(myText);
spannableStringBuilder.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
spannableStringBuilder.removeSpan(this); // This will delete this clickable span
}
},0,myText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(spannableStringBuilder);
myTextView.setMovementMethod(LinkMovementMethod.getInstance());

Meet Vora
- 2,783
- 1
- 16
- 33