TextInputEditText has a limit on the maximum number of characters entered, for example 30. It is necessary that when you enter the @ character, it counts as 2, i.e. if you enter only @, then you can enter no more than 15 characters. How to implement such an algorithm?
CodePudding user response:
solution found, function together with textChanges() RxJava
fun charDoubleLength(string:String, charDouble: Char, editText: EditText, maxLengthLine: Int){
val charCount = string.filter { char ->
char == charDouble
}.count()
val maxLengthEditText= maxLengthLine - charCount
editText.filters =
arrayOf<InputFilter>(InputFilter.LengthFilter(maxLengthEditText))
}