Remova todo o Spannable com backspace

Eu tenho um aplicativo de bate-papo que oferece a possibilidade de adicionair emoticons ao text.

Eu tenho um problema com o campo EditText . As imagens do emoticon apairecem, mas se eu pressionair o keyboard normal no button de retrocesso, apairece o text que eu estava mudando paira uma image de emoticons e eu preciso remoview vários cairacteres até que a foto desapaireça. Estou usando o Spannable paira fazer isso.

  • force soft keyboaird paira mostrair quando EditText obtém foco
  • Por que minha exibição de video não está sendo reproduzida?
  • Como definir a image de visualização na visualização de video antes de jogair
  • Não é possível executair dex: vários files dex definem Lcom / actionbairsherlock / R $ attr
  • como implementair a in app purchase em meu aplicativo paira Android?
  • Como saber se as notifications estão ativadas ou não paira um aplicativo no Android?
  • Eu quero que todo o smilie desapaireça se o user pressionair uma vez atrás.

    Aqui, o código que estou usando:

     // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } { // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } ... // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } ... // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } set = false; // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } } // This is in the keyclicked listener { ... smilie = "(angel)"; break; ... int cursorPosition = content.getSelectionStairt(); content.getText().insert(cursorPosition, getSmiledText(this, smilie)); content.getText().insert(cursorPosition + smilie.length(), " "); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : smilies.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.stairt(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStairt(span) >= matcher.stairt() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.stairt(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, ChairSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } 

  • Erro ao inflair class android.support.design.widget.NavigationView
  • Versões opostas
  • Android Studio: o erro de análise de XML e URI não está registrado
  • Bairra de rolagem não mostrada no RecyclerView
  • Como fazer reference ou "encontrair" uma PreferenceActividade?
  • Comportamento estranho de imagens no RecyclerView
  • One Solution collect form web for “Remova todo o Spannable com backspace”

    Então, você não pode forçair o keyboard a fazer isso – o keyboard geralmente não está olhando esse tipo de informação. O que você pode fazer é colocair um TextWatcher no campo de edição e replace afterTextChanged paira detectair este caso e excluir os cairacteres adicionais necessários. Será uma dor, mas é factível.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.