2014-04-02 13 views
6

Devo controllare se un testo di modifica contiene o meno delle emoticon. Ho provato a creare un osservatore di testo in cui ho controllato se è presente uno span di immagini ma non riesco a ottenere alcun risultato.Come verificare se un EditText in Android ha emoticon o no?

SpannableStringBuilder s = new SpannableStringBuilder(source.toString()); 
ImageSpan a[]= s.getSpans(0,s.length(), ImageSpan.class); 

if(a.length!=0){ 
    Toast.makeText(NewEpisodeActivity.this, R.string.invalid_char, Toast.LENGTH_SHORT).show(); 
    return ""; 
} 

risposta

0

Si dovrebbe prendere hasmap con codice emoticon come immagine chiave ed emoticon come valore. Ora controllare per il testo se è il codice emoticon Se sì allora

s.setSpan(new ImageSpan(Context, Emoticons_Image, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
0

Do check-in non in onTextChanged()

private TextWatcher textChangedListener = new TextWatcher() { 

    @Override 
    public void afterTextChanged(Editable editable) { 
     final ImageSpan[] itemSpans = editable.getSpans(0, editable.length(), ImageSpan.class); 
     final boolean hasEmoticons = itemSpans != null && itemSpans.length > 0; 
    } 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, int count) { 
    } 

    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    } 

}; 
Problemi correlati