B4J Question [SOLVED] Combobox value change check length when writing to it..

Magma

Expert
Licensed User
Longtime User
Hi there...

I wanna check the length of a combobox editable value... when writing...

I thought was simple but the only way to check combobox value is after pressing enter !

B4X:
Sub fromwhere_ValueChanged (Value As Object)

Dim s As String
s=Value
If s.Length<1 Then
    CSSUtils.SetBackgroundColor(fwc, fx.Colors.red) 'fwc is a kind of lamp (act.label) :-)
End If
If s.Contains(fromwhereold.Trim)=False Then
    CSSUtils.SetBackgroundColor(fwc, fx.Colors.red)
End If

End Sub

Tried and keypressed ... but the same...
Tried Timer the same too...

Any IDEA - can i check it with javaobject or something (the editable value) ?
 

stevel05

Expert
Licensed User
Longtime User
Try this :
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private ComboBox1 As ComboBox
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show

    CallSubDelayed(Me,"SetupListeners")
  
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Private Sub SetupListeners
    Dim CBJO As JavaObject = ComboBox1
    Dim TI As JavaObject = CBJO.RunMethod("lookup",Array(".text-input"))
    If TI.IsInitialized Then
        Dim TProp As JavaObject = TI.RunMethod("textProperty",Null)
        Dim O As Object = TProp.CreateEventFromUI("javafx.beans.value.ChangeListener","CBTextChanged",Null)
        TProp.RunMethod("addListener",Array(O))
    Else
        Log("EditText Not found or ComboBox is not editable")
    End If
End Sub

Private Sub CBTextChanged_Event (MethodName As String, Args() As Object)
    Dim Old As String = Args(1)
    Dim New As String = Args(2)
  
    Log("Old " & Old)
    Log("New " & New)
End Sub

Test project attached, the layout just holds a Combobox which must be set editable.
 

Attachments

  • CBTest.zip
    2 KB · Views: 203
Upvote 0
Top