Search code examples
androideclipseandroid-edittext

stop user from inputting in to the edit box?


i want the EidtText to stop accepting input from the user if the input text length is more than 10 ..but it should be able to delete the already available text in the EditText even though the text length is more than 10 ...

can some one help me with the code pls..

thanks :)


Solution

  • Have you tried limiting the number of character of the EditText ? If not take a look at this

    EditText et = new EditText(this);
    
    int maxLength = 3;
    
    InputFilter[] FilterArray = new InputFilter[1];
    
    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
    
    et.setFilters(FilterArray);