Note that there are some explanatory texts on larger screens.

plurals
  1. POText is messed up with ImageSpan in EditText
    primarykey
    data
    text
    <p>I am building a simple chat app where the user has the ability to send text and emoticons. I can send both text and emoticons to another phone. My problems are:</p> <p><strong>1.When I type something and add an emoticon:</strong></p> <p><img src="https://i.stack.imgur.com/5GUfd.png" alt="enter image description here"></p> <p>Then I cannot type any text right before and right after the image. I can write before the "o" letter. The system "sees" that I type, so even if I type "Honey" after the smiley, I cannot see it, but the EditText registers it and the message is sent:</p> <p><img src="https://i.stack.imgur.com/NxnMZ.png" alt="enter image description here"></p> <p><strong>2.When I add just an emoticon to the Edittext then I delete it</strong>, I cannot type anything because the deleted emoticon appears. It appears only once, so no matter how many characters I type, the EditText looks like just before I deleted the emoticon, BUT the text is sent without the emoticon, just like in all three cases.</p> <p><strong>3.When I type "something" in the EditText then insert an emoticon after "some":</strong></p> <p><img src="https://i.stack.imgur.com/FgfXT.png" alt="enter image description here"></p> <p>Then I put the cursor after the emoticon and delete it, here what's left:</p> <p><img src="https://i.stack.imgur.com/Z2xgI.png" alt="enter image description here"></p> <p>But the correct message is sent when I press the Send button:</p> <p><img src="https://i.stack.imgur.com/9nMbA.png" alt="enter image description here"></p> <p>That's what's inside the button listener of the emoticon (this method is activated when I click the emoticon to add it to the EditText).</p> <pre><code>ib_happy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int cursorPosition = mOutEditText.getSelectionStart(); mOutEditText.getText().insert(cursorPosition, smileys[0]); SpannableStringBuilder ssb = new SpannableStringBuilder(mOutEditText.getText()); ssb.setSpan(new ImageSpan(bitmapArray.get(0), ImageSpan.ALIGN_BASELINE), cursorPosition, cursorPosition+2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); mOutEditText.setText(ssb, BufferType.SPANNABLE); mOutEditText.setSelection(cursorPosition+2); dialog_emoticon.dismiss(); } }); </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