Android Question Validate the minumum value in a EditText

Antonio Ferreira

Member
Licensed User
Longtime User
How can i validate a numeric minimum value in a EditText on a xcustomlistview (with lazy loading)
Validating the maximum value is easy with EditText_Textchanged event.

Thanks
 

Antonio Ferreira

Member
Licensed User
Longtime User
But this does not depend on the EditText being inside a CustomListview.

B4X:
'Not tested

Private EditText1_TextChanged (Old As String, New As String)
    If New.Length > 1 And New.As(Int) < 50 Then
        xui.MsgboxAsync("At least 50", "B4X")
        EditText1.Text = Old
    End If
End Sub
Validate the minimum value with EditText1_TextChanged (Old As String, New As String) i always have the warns that the value is less than the minimum.
in your example:
- if ! want to write 272 in the editText, when i write the second digit (27) the EditText1_TextChanged event warns me that the value is less than the minimum.
- if i only write 2 in the editText i don´t have the validate error message.

Validate with EditText1_FocusChanged on in a xcustomlistview with lazy loading is not simple.

it's not worrying. i just have to live with it

Thank you for the reply.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Validate the minimum value with EditText1_TextChanged (Old As String, New As String) i always have the warns that the value is less than the minimum.
in your example:
- if ! want to write 272 in the editText, when i write the second digit (27) the EditText1_TextChanged event warns me that the value is less than the minimum.
- if i only write 2 in the editText i don´t have the validate error message.

Validate with EditText1_FocusChanged on in a xcustomlistview with lazy loading is not simple.

it's not worrying. i just have to live with it

Thank you for the reply.
My code avoids the problem you highlighted, with the single digit example.
It is clear that you cannot use the Changed event in other cases, like the one you wrote above. You will need to add a button to submit changes.

Again, the CustomListView has nothing to do with the problem.
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
i just have to live with it

What about if you do the limit check when the user "leaves" the field ie on FocusChange or LostFocus event?

Admittedly, isn't quite as instantaneous at letting user know there is a problem.

On the other hand, isn't stepping on their fingers prematurely either. 🍻
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Here I made the check to happen after 1 second without writing into the edittext.
So there is time to input more than 1 digit.
 

Attachments

  • ETMinMax.zip
    14.1 KB · Views: 95
Upvote 0
Top