title: Last character gets unspanned after applying two spans on a selected text in edittext
body: <p>This problem is pretty annoying so Iam going to trace it down bit by bit so you can understand it fully:-</p>
  
  <p>First I select the last word in my edit text like so:-</p>
  
  <p><a href="https://i.stack.imgur.com/KgkEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KgkEU.png" alt="enter image description here"></a></p>
  
  <p>So far so simple then I make the text bold by clicking a button (setting a bold span) like so:-</p>
  
  <p><a href="https://i.stack.imgur.com/IbWN6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IbWN6.png" alt="enter image description here"></a> </p>
  
  <p>The underline is just the default text correction in the softkeyboard. Then I reselect the text:-</p>
  
  <p><a href="https://i.stack.imgur.com/N6rtc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N6rtc.png" alt="enter image description here"></a></p>
  
  <p>Then when I make it italic the same way (setting italic span by pressing a button) I get this:-</p>
  
  <p><a href="https://i.stack.imgur.com/So1jv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/So1jv.png" alt="enter image description here"></a></p>
  
  <p>The last character gets unspanned from bold .This happens only in this specific situation when I <strong>select</strong> the word and the word is at the <strong>end</strong> of the edittext.</p>
  
  <p>Also I found out that this problem occurs when the spans are set for each char if its for the whole word it doesn't happen (for both bold and italic):-</p>
  
  <pre><code>//for each char
  for (int i = 0; i &lt; token.length(); i++) {//token is the word
  SpannableString char = (SpannableString) token.subSequence(i, i + 1);
  
  char.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, 
  char.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  }
  </code></pre>
  
  <p>But if whole word problem doesn't happen:-</p>
  
  <pre><code>// for the whole word 
  
  token.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, 
  token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  }
  </code></pre>
  
  <p>But of course the user can set spans for a char so the problem is still relevant else no problem occurs if the word is not selected at the end of the edit text .</p>