I'm adding an image to my edittext by inserting an ImageSpan. I don't have a thorough understanding of spans but it seems that my ImageSpan needs to wrap a portion of text. So I add some text to the EditText, and wrap it with my ImageSpan and it appears fine. However, when I backspace the ImageSpan, it only deletes one character of the text and the image remains until the entire text is delete. How do I get it to just delete with one backspace?
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(content.getText());
String imgId = "[some useful text]";
int selStart = content.getSelectionStart();
builder.replace(content.getSelectionStart(), content.getSelectionEnd(), imgId);
builder.setSpan(imageSpan, selStart, selStart+imgId.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(builder);