How to check if EditText in Android has a smiley or not?

I need to check if there is any emoticon in the edit text or not. I tried to make a text observer in which I checked if a range of images was present, but I could not get any results.

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 ""; } 
+6
source share
2 answers

You should use the hasmap with the emoticon code as a key and blurry image as a value. Now check the text if it is an emoticon code, if so, then

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

Check afterTextChanged(Editable editable) not on 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) { } }; 
0
source

All Articles