Muhammadjon
Muhammadjon

Reputation: 1506

How to get maxLength of EditText

I set the max length of EditText by writing the following in XML file

android:maxLength="16"

I want to get this length programmatically (inside TextWatcher). I got one answer using How to Get EditText maxLength setting in code link, however, it is not what I want because it does not work when the maxLength is changed in runtime.

How can I get the length of EditText programmatically? (MinSDKVersion is 14)

Upvotes: 1

Views: 651

Answers (1)

Shubham Vala
Shubham Vala

Reputation: 1043

create integer in integers.xml and get set that value in EditText like this,

In integers.xml

<item name="max_char">16<item>

set in EditText like this

android:maxLength="@integer/max_char"

get integer in Javafile like this

int maxChar = getResources().getInteger(R.integer.max_char);

Upvotes: 1

Related Questions