My IM app has to support emoticons. They are GIFs and have textual representations, which are used in the input box if the user selects one of them. But I'd like to display them as images after they have been sent.Currently my custom array adapter displays the sent message in a TextView of a row.
What is the proper method to display images dynamically based on the occurrence of their textual representation? Do I have to search for emoticon texts, and if one found, remove the TextView from the layout (relativeLayout fits most?) and add a TextView with the beginning of the IM, an ImageView with the emoticon and another TextView. If more emoticons sent simultaneously it can be messy.
Is there an easier and more logical way?
I think it would be more useful to build
Spannable
.Actualy this code based on sources from native
Html
class.Edit: Updated version has dramatic speed improvement.
I would try using a regular expression to replace all occurrences of each emoticon with an
<img>
tag. Then, convert that HTML into aSpannedString
viaHtml.fromHtml()
. ThatSpannedString
can be used in asetText()
call onTextView
.