androidandroid-edittextimagespan

How to append multiple ImageSpans on an EditText?


I'm looking for implementing Android Chips on my application. Everytime user types 3 chars it is checked if the typed string corresponds to an existing POJO and, if so, a request to add a Chip is made. The request finishes at this method:

val bd = mRootView.getDrawable()
bd.setBounds(0, 0, bd.intrinsicWidth, bd.intrinsicHeight)
sb = SpannableStringBuilder("$mReplaceable ")
setSpan(ImageSpan(bd), 0, mReplaceable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
setText(sb)
setSelection(mInput.text.length)
isAddingChip = false

Code details can be found on GitHub

The problem is that the everytime I add a new Chip (ImageSpan), the old one is replaced to the recently added. Can anyone help me to spot where the problem is?


Solution

  • It looks like it is not possible doing that. What I've made was to inflate my custom layout, save a bitmap from it and place the result in one ImageSpan.