EditText maxLength property not applied properly when setFilters is used

后端 未结 4 1880
暗喜
暗喜 2021-01-03 05:40

When I use setFilter method on an EditText to handle special characters, maxLength property is not working as expected. My code is be

4条回答
  •  心在旅途
    2021-01-03 06:02

    while setting maxlenth property of edittext programatically

    please show use the code.

    Wild Guess: the problem may be that you set the maxLength in the layout. By calling setFilters() this behavior is replace by the one of your Filter.

    Solution: use more that one filter or implement the maxLenght behavior in your getFilteredChars() filter.

    EDIT: you may want to look at http://developer.android.com/reference/android/text/InputFilter.LengthFilter.html

    and for you question in the comment, from the doc:

    when the buffer is going to replace the range dstart … dend of dest with the new text from the range start … end of source
    

    so, something like (Pseudo code liveCoding) :

    dest.lenght - (dend-dstart) + (end-start)  = new legnth
    

提交回复
热议问题