1

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)

Muhammadjon
  • 1,476
  • 2
  • 14
  • 35

1 Answers1

1

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);
Shubham Vala
  • 1,024
  • 7
  • 18