-3

I'm using an EditText Field in my app where the user can specify an amount of money.

I want to set that user can not enter more than 1000000 money.

Is there a way to limit the value?

komal akhani
  • 553
  • 6
  • 20
  • No.It is not duplicate@DharmbirSingh – komal akhani Jul 24 '17 at 06:25
  • you need to apply a textwatcher and there you need to check your condistions accordingly – King of Masses Jul 24 '17 at 06:26
  • You can't set maximum "integer" value for EditText. Instead, you can use [addTextChangedListener(android.text.TextWatcher)](https://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher)) to observe when text changed and make the change you desire. – BakaWaii Jul 24 '17 at 06:49
  • @BakaWaii No,you are wrong.because we can set "integer" value for edittext without using addTextChangedListener(android.text.TextWatcher). – komal akhani Jul 24 '17 at 11:20

1 Answers1

5

you can use in java

editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)});

or in xml

  <EditText
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:maxLength="13"/>
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78