views:

225

answers:

1

Hi!

My IM app has to support emoticons.
They are gif-s, 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 TextVew.
If more emoticons sent simultaneously it can be messy.

Is there an easier and more logical way?

Thanks for every answer!

+3  A: 

I would try using a regular expression to replace all occurrences of each emoticon with an <img> tag. Then, convert that HTML into a SpannedString via Html.fromHtml(). That SpannedString can be used in a setText() call on TextView.

CommonsWare
That works, thanks a lot!