Android Question requestfocus inside enterpressed is ignored

Domingo Garcia

Member
Licensed User
I have a routine that should set the focus to a previous text field (txtSku) but it ignores the requestfocus and sets focus to the next text field txtReturns. Is there any restrictions on using the requestfocus.

B4X:
Sub txtBuy_EnterPressed
    Dim sBuy As String
    
    If txtBuy.Text.length >10  Then
        txtSku.Text = txtBuy.Text
        txtBuy.Text = ""
    Else
        If HaveProduct Then
            sBuy =txtBuy.Text
            If sBuy = "0" Then
                Buy = 0
                AddDetail               'Used for Deleting Sales Entry
            Else
                Buy = Itz(txtBuy.Text)
                If Buy <> 0 Then
                    If Buy < 0 Then
                        txtBuy.Text = ""
                    Else
                        AddDetail
                    End If
                   End If
            End If
        End If
    End If   
    txtSku.RequestFocus       
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Create a sub and call it with CallSubDelayed
Inside the sub you can request the focus to another field.

Something like

B4X:
Sub changefocus()
    txtSku.RequestFocus
End Sub
Sub txtBuy_EnterPressed
    Dim sBuy As String
    
    If txtBuy.Text.length >10  Then
        txtSku.Text = txtBuy.Text
        txtBuy.Text = ""
    Else
        If HaveProduct Then
            sBuy =txtBuy.Text
            If sBuy = "0" Then
                Buy = 0
                AddDetail               'Used for Deleting Sales Entry
            Else
                Buy = Itz(txtBuy.Text)
                If Buy <> 0 Then
                    If Buy < 0 Then
                        txtBuy.Text = ""
                    Else
                        AddDetail
                    End If
                End If
            End If
        End If
    End If
    CallSubDelayed(Me,"changefocus")
End Sub
 
Upvote 0
Top