display smiley in textview and edittext in android

Ramesh Solanki picture Ramesh Solanki · Feb 17, 2012 · Viewed 13.4k times · Source

hello i am developing chat application in which i want to insert smiley i have not much idea about it how to integrate and display in it can u give me suggestion for doing the same ?

ImageGetter imageGetter = new ImageGetter() {
    public Drawable getDrawable(String source) {
        Drawable d = getResources().getDrawable(
                R.drawable.happy);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        return d;
    }
};

cs = Html.fromHtml(
        "<img src='"
                + getResources()
                        .getDrawable(R.drawable.happy)
                + "'/>", imageGetter, null);
System.out.println("cs is:- " + cs);
edttxtemoji.setText(cs);

i found this code, in this it uses images, is this feasible ? or there is another solutions ? please give me better solution for this thanx in advance

Answer

Lalit Poptani picture Lalit Poptani · Apr 9, 2012

Yes there is another way for showing smiley within the TextView or EditText. Build a Spannable text using ImageSpanand then setText the Spannable to TextView or EditText. Here is an post for the same.