B4J Question [Solved]Spinner Value to TextField Focus

rodmcm

Active Member
Licensed User
Porting a program from B4a to B4j
One part of program can have changing number of textfield boxes. I use FocusChanged() to identify which textbox is active and in some cases use a spinner to allow user to only choose from a known list

I have defined a Process Variable
B4X:
Private EditTxtFocus As TextField

Initialize it
B4X:
EditTxtFocus.Initialize("editFocus")

Use the following to select the spinner
B4X:
' Selects the edit textfield touched
Sub edtEdit_FocusChanged (HasFocus As Boolean)      
    If HasFocus Then
        EditTxtFocus = Sender
        spEquipment.Visible=False
        If DBName = "RAWTERMS" Then
            If EditTxtFocus.Tag = 0 Or EditTxtFocus.Tag = 4 Then       ' tags assigned numerically as edtEdit textfields created on pane
                spEquipment.Left = edtEdit(EditTxtFocus.Tag).Left       ' places spinner near edtEdit textfield 
                spEquipment.Top = edtEdit(EditTxtFocus.Tag).Top
                spEquipment.Visible = True
            End If
    Else
        EditTxtFocus.Enabled=True
        EditTxtFocus=Null
    End If
End Sub

Which works fine and then this to attach the spinner value to the editTxtfocus.text
B4X:
Sub spEquipment_ValueChanged (Value As Object)
    Log(spEquipment.Value)
    EditTxtFocus.Text=spEquipment.Value
End Sub

This does not work the error is :
java.lang.RuntimeException: Object should first be initialized (TextField).

Can someone please explain why it is not working. The B4a version works fine
 

Daestrum

Well-Known Member
Licensed User
Longtime User
I would try commenting out this line
B4X:
EditTxtFocus=Null

The reason (as I see it)
1, you click on textfield which then gains focus
2, the spinner pops up ( but steals focus )
3, the textfield loses focus so sets EditTextFocus to null
4, spinner tries to pass value to a 'nulled' textfield

Maybe change to
B4X:
EditTxtFocus.Text=""
 
Upvote 0
Top