0

I am using Edittext which is allowed to specific characters. Like a-z A-Z 0-9 and Special characters like )&'(".

For the above requirement I used digits in Edittext to restrict rest of the other special characters getting typed.

The digits not supported ' & " chars so I used html code &apos ; &amp ; &quot ; respectively.

Now the problem is I want to allow accent characters too. I found the html code for accent Á is &Aacute ; but digits is showing error like

" The entity "Aacute" was referenced, but not declared. ".

Kindly provide any solution for this or Is there any solution to allow accent character with a-z,A-Z,0-9 and 5 special character )&'(" in Edittext?

Dhamodharan
  • 195
  • 1
  • 2
  • 20
  • have you seen this: http://stackoverflow.com/questions/3349121/how-do-i-use-inputfilter-to-limit-characters-in-an-edittext-in-android? – anil May 21 '15 at 06:47

2 Answers2

1
InputFilter filter = new InputFilter() { 
    public CharSequence filter(CharSequence source, int start, int end, 
    Spanned dest, int dstart, int dend) { 
            for (int i = start; i < end; i++) { 
               if ( !Character.isLetterOrDigit(source.charAt(i)) || Character.toString(source.charAt(i)) .equals(")") || 
                 !Character.toString(source.charAt(i)) .equals("(")  ||
                !Character.toString(source.charAt(i)) .equals("\'")  ||
                !Character.toString(source.charAt(i)) .equals("&")  ||
                !Character.toString(source.charAt(i)) .equals("&")) { 
                            return ""; 
                    } 
            } 
            return null; 
    } 
}; 

edit.setFilters(new InputFilter[]{filter}); 
Kartheek
  • 7,104
  • 3
  • 30
  • 44
  • I already aware of this, when I use this while typing and press space it automatically uses suggested words. Ex If you type "appl" and pressing space it automatically turn into "applied" – Dhamodharan May 21 '15 at 07:10
  • Set this in your layout's xml for your EditText: android:inputType="textNoSuggestions" Or call setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) in your Activity' If you need to support API 4 and below, use android:inputType="textFilter" – Kartheek May 21 '15 at 07:18
  • Good suggestion on inputtype. finally it works with below java code with your suggestion. – Dhamodharan May 21 '15 at 07:36
  • The java code not used from yours instead I use another one any way I accept this answer. – Dhamodharan May 21 '15 at 08:49
0

much easier:

    <EditText
        android:digits="0123456789qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM"
        android:inputType="text" />

Here in this digits: add your accent characters too

Just a word of caution, the characters mentioned in the android:digits will only be displayed, so just be careful not to miss some out :)

King of Masses
  • 18,405
  • 4
  • 60
  • 77