Monday, 15 August 2011

android - Remove whole Spannable with backspace -


I have a chat app that gives the possibility of adding text to an emoticon.

I have a problem with a EditText field, emoticon images are shown, but if I press the backspace button on the normal keyboard, the text I was turning into an emoticons photo By then I have to find and I have to remove many characters till the picture is removed. I am using Spannable to do this.

I want to be completely smiling, if the user once presses the backspace

Here I am using the code:

  / / This keyclicked listener is in {... smilie = "(angel)"; break; ... int cursor post = content.getSelectionStart (); Content.getText () Insert (cursor position, get supported text (this, smileys)); Content.getText () Insert (cursor mode + smilie.length (), ""); } Public stable boolean addSmiles (Reference Reference, Spannable Spannable) {Boolean hasChanges = false; (Entry  entry: smilies.entrySet ()) {mater matcher = entry.getKey (). Matcher (spannable); While (matcher.find ()) {boolean set = true; (Image span duration: spannable.getSpans (matcher.start), matcher.end (), ImageSpan.class)) (spannable.getSpanStart (span)> = matcher.start () & amp; amp; Spannable.getSpanEnd () period) & lt; = Matcher.end ()) spannable.removeSpan (span); Else {set = false; break; } If (set) {hasChanges = true; Spannable.setSpan (New ImageSpan (reference, entry .getValue ()), matcher.start (), matcher.end (), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }}} There are changes in the change; } Public Stable Spannable getSmiledText (Reference Reference, Charsequence Text) {Spannable spannable = spannableFactory.newSpannable (text); AddSmiles (context, spannable); Return span; }    

so that you can not force the keyboard to do this - the keyboard is usually But not seeing that kind of information. What you can do is place a TextWatcher on the editing field and afterwards override the text after detecting it and removing the required additional characters. It can be a pain but it's worth it.

No comments:

Post a Comment