I want to detect whether my EditText
contains smilie (emoticons) or not. But I have no idea that how to detect them.

- 818
- 1
- 11
- 29

- 81
- 1
- 5
-
by similes I mean emoticons. – Vivek Chahar Jun 25 '15 at 05:41
-
Have you tried typing emoticons in the edittext and see what text it contains with EditText.getText() – Ivo Jun 25 '15 at 05:57
3 Answers
To disable emoji characters when typing on the keyboard I using the following filter:
InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
int type = Character.getType(source.charAt(i));
//System.out.println("Type : " + type);
if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
return "";
}
}
return null;
}
};
mMessageEditText.setFilters(new InputFilter[]{filter});
If you need only detect if EditText contains any emoji character you can use this priciple (Character.getType()
) in android.text.TextWatcher
interface implementation (in onTextChange()
or afterTextChanged()
method) or e.g. use simple for
cycle on mMessageEditText.getText()
(returns CharSequence class) with charAt()
method.

- 1,263
- 12
- 18
-
2
-
But if using the filter, there is another bug that will exist. First type something, then enter emoji, then press back space, 2 characters will be deleted instead of 1 – HendraWD Jun 08 '17 at 17:23
-
1Nice, but sadly, this also excludes a lot of other special characters like © ® ™ ℅, Chinese symbols and even the tactile alphabet. – 0101100101 Jul 07 '17 at 06:07
-
You may also would like to add more character types to this method, like Character.ENCLOSING_MARK, Character.MATH_SYMBOL, Character.OTHER_PUNCTUATION, Character.DASH_PUNCTUATION, Character.MIN_RADIX – Kirill Kostrov Mar 28 '23 at 18:33
If by simile
you are referring to the figure of speech, you can use .getText()
and the String
method .contains(String)
to check whether it contains the Strings "like" or "as".
Snippet:
EditText myEditText = (EditText)findViewById(R.id.myEditText);
String input = myEditText.getText();
if(input.contains("like") || input.contains("as"))
{
//code
}

- 206
- 3
- 11
It depends the way you are implementing simleys in your edittext. if you are using motioons you can do this using a trick. You can set a condtion whenever a simpley a added you can add some type of keyword to arrayList and whenever smiley is remover you can remove that keyword from arrayList. And at last you can check that list whether that simley is added to it or not by processing the arrayList items.
for ex...
if(Smiley_added){
arraylist.add(smiley_code,i);
}
if(simley_removed){
arraylist.remove(smileycode,i);
}
if(arraylist.get(i).equals("smileyCode")){
do this....
}

- 1,941
- 3
- 21
- 34
-
I want want to detect if emoticons are present or not ,and then on sending to server i want to remove them so how large can be the map of similes and also this method will be hardcoded if i check for every emoticons via building a map of emoticons vs code. – Vivek Chahar Jun 25 '15 at 06:00