Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have solution for that. Put following code which add smiles in your text view.</p> <pre><code>private static final Factory spannableFactory = Spannable.Factory .getInstance(); private static final Map&lt;Pattern, Integer&gt; emoticons = new HashMap&lt;Pattern, Integer&gt;(); static { addPattern(emoticons, ":)", R.drawable.happy); addPattern(emoticons, ":(", R.drawable.sad); addPattern(emoticons, ":D", R.drawable.very_happy); // ...as many pattern you want. But make sure you have images in drawable directory } private static void addPattern(Map&lt;Pattern, Integer&gt; map, String smile, int resource) { map.put(Pattern.compile(Pattern.quote(smile)), resource); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry&lt;Pattern, Integer&gt; entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) &gt;= matcher.start() &amp;&amp; spannable.getSpanEnd(span) &lt;= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, CharSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } </code></pre> <p>After doing copy paste, write following code to set smiles in your text view.</p> <pre><code>textView.setText(getSmiledText(ActivityName.this,"Hi :) How are you...??? :D I am very :(")); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload