Amintabar
Amintabar

Reputation: 2266

How to set the maxLength property of an EditText programmatically in Kotlin?

I would like to programmatically set the maxLength property of EditText as I don't want to set it in the layout file. I can't see any set method related to maxLength.

Upvotes: 0

Views: 661

Answers (1)

Amintabar
Amintabar

Reputation: 2266

You must set it as an input filter, and can set an array of input filter in same time.

You can set the maxLenght like this code:

field.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(data.maximum ?: 0))

Upvotes: 1

Related Questions