0

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 ?

Utsav Gupta
  • 3,785
  • 5
  • 30
  • 52

1 Answers1

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