0

is there a way to block characters like ä which appear on long press of keys like a,e,i etc in android using input filter.

1 Answers1

0

Hope it will help you

private EditText editText;
private String characterSet = "give_blocking_charset_here";

private InputFilter filter = new InputFilter() {

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

        if (source != null && characterSet.contains(("" + source))) {
            return "";
        }
        return null;
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editText = (EditText) findViewById(R.id.editText);
    editText.setFilters(new InputFilter[] { filter });
}
Vijaya Varma Lanke
  • 603
  • 2
  • 7
  • 19
  • I am hoping for a more generic answer as I cant add or dont know all character types which appear on long press of a key and also if I use the above for character set like "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ", if i type "aa" it will be rendered as blank. – Tenzin Younten Taktsak Oct 05 '18 at 10:36