1

I have an editText that i want to control in length.

how can i avoid the user from entering a character which will lead the text to be longer than X ?

I have thought to use beforeTextChanged(CharSequence s, int start, int count, int after) {

but then i'm not sure how to skip adding the character if i want.

The length is determined dynamically - getting this from the server side on activity start

Elad Benda2
  • 13,852
  • 29
  • 82
  • 157

2 Answers2

1

Well, if you need to stop the user from entering a text longer than x, simply put android:maxLength="x" as an attribute for your EditText.

Or,

mEditText.setFilters( new InputFilter[] { new InputFilter.LengthFilter(<length>) } );

Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
Swayam
  • 16,294
  • 14
  • 64
  • 102
0

use following property in edittext

android:maxLength="10"
jack
  • 338
  • 1
  • 3
  • 29