Smiley Apps for Android Chat
You can achieve this using ImageSpan objects. TextViews and EditTexts use Spanned / Spannable objects to store typed text content, not just java strings. On these Spanned / Spannable objects, you can define spacing for sections of text that change how those sections are displayed. This way you can display text in bold, italic, etc., and also you can display images instead of specific sections.
So you can find the ":-)" pattern in the entered text and tickle the ImageSpan by displaying an emoticon. Check docs http://developer.android.com/reference/android/text/style/ImageSpan.html .
source to share
We cannot add an image directly to editText and textView. for this we have to make the text spannable and my code creates spannable text and now you can set it in textView / editText.
ImageGetter imageGetter = new ImageGetter()
{
public Drawable getDrawable(String source) {
Drawable d = getResources().getDrawable(R.drawable.e001);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.e001) + "'/>", imageGetter, null);
yourTextView.setText(cs);
source to share