0

I am working on a chat application where i am implementing emoji but i have one question in adapter how to render the emoji in a Textview.

emocationGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            emoDrawables.get(position).setBounds(0, 0, emoDrawables.get(position).getIntrinsicWidth(),
            emoDrawables.get(position).getIntrinsicHeight());

            int selectionCursor = chatMsgEtd.getSelectionStart();
            chatMsgEtd.getText().insert(selectionCursor, ".");
            selectionCursor = chatMsgEtd.getSelectionStart();

            SpannableStringBuilder builder = new SpannableStringBuilder(chatMsgEtd.getText());
            builder.setSpan(new ImageSpan(emoDrawables.get(position)), selectionCursor - ".".length(),
                    selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            chatMsgEtd.setText(builder);
            chatMsgEtd.setSelection(selectionCursor);
        }
});

Adapter

chatMsgTxt.setText(chats.get(position).getMessage());

So in the adapter the getMessage is the chat message but here how to render the emoji with message.

Please go through my post and suggest me some solution.

Anshuman Pattnaik
  • 883
  • 3
  • 16
  • 37

1 Answers1

0

You can set a span on your TextView, most likely you want to extend DynamicDrawableSpan and source the images into the span. If your goal is to render iOS emojis instead of the default android ones you should use a library like https://github.com/instachat/emoji-library or https://github.com/rockerhieu/emojicon

pat
  • 1,005
  • 4
  • 12
  • 29