2
street = (EditText) findViewById(R.id.street);
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.isSpaceChar(source.charAt(i))) { 
                 return "";     
             }     
        }
        return null;   
    }  
};
street.setFilters(new InputFilter[] { filter });

my edittext is able to filter character & number on the virtual keyboard but not taking the space character.. plz help

Dan
  • 3,884
  • 3
  • 27
  • 32
swapnil
  • 51
  • 1
  • 4

3 Answers3

3

instead of '||' i replaced with '&&' and got the answer....

swapnil
  • 51
  • 1
  • 4
0

Use this condition

for (int i = start; i < end; i++) { 
    if (!Character.isLetterOrDigit(source.charAt(i))) {
        if (!Character.isSpaceChar(source.charAt(i)))
            return "";
    }
}
N. N
  • 19
  • 6
0
!Character.isLetterOrDigit(source.charAt(i)) || Character.isSpaceChar(source.charAt(i))

Is the code you want assuming you DONT want white space characters and only numbers or characters.

Todd Painton
  • 701
  • 7
  • 20