0

I'm working on an Android project which sends datas to my webservice et stores them in my database.

I added an edit text field which allow the user to put some comments. But some character like the quotes are replaced by a question mark in a lozenge when datas arrived in the webservice.

So I implement an method which use the function "replace" to replace the special character by "".

My question: is there another way to delete them of my keyboard (in order to prevent to use these characters)? Or the user can press on it but without action.

EDIT 1:

Finally is it possible to allow these characters:

  • [a-z]
  • accented characters
  • [A-Z]
  • [0-9]
  • ?,.;/:!%*-+_ {}() [] ...

And replace the other one by " "

13KZ
  • 1,295
  • 5
  • 24
  • 43
  • 4
    I'd rather fix the encoding bug you have there ;) – Fildor Jan 08 '13 at 09:56
  • You can design your own keyboard. I suspect that's not a good idea. ;) – Peter Lawrey Jan 08 '13 at 09:57
  • 1
    look at this post you can customize it yourself http://stackoverflow.com/questions/9577304/how-to-make-a-android-custom-keyboard – Talha Jan 08 '13 at 09:59
  • thanks for your answers. I'm not trying to design my keyboard but I just want to block the action of special character – 13KZ Jan 08 '13 at 10:10
  • Finally I'm using android:digits in my xml file (EditText part) to define the characters that I allow. Impossible to tape on the other one which aren't in the definition. For example android:digits="ABCDEFGHIJKL..abcdefghijklmnopq....0123.." – 13KZ Jan 15 '13 at 10:59
  • 2
    Does this answer your question? [Android - is it possible to hide certain characters from the soft keyboard?](https://stackoverflow.com/questions/10536839/android-is-it-possible-to-hide-certain-characters-from-the-soft-keyboard) – Josh Correia Jul 18 '20 at 23:17

1 Answers1

2

to block the special chars you can use setFilters of the edit text like this.

   InputFilter[] myfilters = new InputFilter[1];
            myfilters[0] = new InputFilter() {
                @Override
                public CharSequence filter(CharSequence source, int start,
                        int end, Spanned dest, int dstart, int dend) {
                    if (end > start) {
                        if (dest != null) {
                        //do some filter
                        }
                    }
                    return null;
                }
            };

            editText.setFilters(myfilters);
Raj
  • 1,843
  • 2
  • 21
  • 47