B4J Question TextChanged Event fired from Pgm code or from User Input

MList

Active Member
Licensed User
TextChanged:
Public txtSeriennummer As B4XView
Sub txtSeriennummer_TextChanged (Old As String, New As String)
    
    If New <> Old Then
       If IsNumber(New) = False Then
            xui.MsgboxAsync(Language.Text(Var.v,37),Language.Text(Var.v,148))
          txtSeriennummer.Text = Old
       Else
           NummerChanged = True     
       End If
    End If
    
End Sub

Hi, the code above is part of a class. For each layout i made a seperate class.
Now i must know if the Textchanged Event fired because the user entered data on the screen or because my
my mainpgm filled it via
CInfo.txtSeriennummer.Text = wertint(0) --> these statements are queued, and i dont know exactly when they will be done

How do i know what happend ?

Thanks a lot for help !
 
Solution
1. No simple way.
2. Your code is likely to annoy the user. Especially with the msgbox.

Different approach:


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XFloatTextField1 As B4XFloatTextField
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XFloatTextField1.Tag = B4XFloatTextField1.HintText
    B4XFloatTextField1.AnimationDuration = 0
    SetTextFieldState(B4XFloatTextField1, True)
End Sub


Private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    Dim valid As Boolean = New = "" Or IsNumber(New)...

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. No simple way.
2. Your code is likely to annoy the user. Especially with the msgbox.

Different approach:


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XFloatTextField1 As B4XFloatTextField
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XFloatTextField1.Tag = B4XFloatTextField1.HintText
    B4XFloatTextField1.AnimationDuration = 0
    SetTextFieldState(B4XFloatTextField1, True)
End Sub


Private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    Dim valid As Boolean = New = "" Or IsNumber(New)
    SetTextFieldState(Sender, valid)
End Sub

Private Sub SetTextFieldState(tf As B4XFloatTextField, valid As Boolean)
    If valid Then
        tf.TextField.SetColorAndBorder(xui.Color_White, 1dip, xui.Color_Gray, 5dip)
        tf.HintText = tf.Tag
    Else
        tf.TextField.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_Red, 5dip)
        tf.HintText = "invalid number"
    End If
    tf.Update 'needed because we update the hint text
End Sub
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…