B4J Question Why is a textfield gets focus

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a problem with textfield . There is a textfield in my app added to scrollpane , this textfield is sometimes selected by itself altough I do nothing , it gets the focus and the pointer is blinking at the textfield and ready to be entered a value. I only have this realted to textfield :

B4X:
Sub txtadet_FocusChanged (HasFocus As Boolean)
    Dim txt As TextField=Sender
   
    If HasFocus=False Then
        txtadet(txt.Tag).Text=txtadet(txt.Tag).Text.Replace(",",".")
        kvsmycoins.Put(listmycoins.Get(txt.Tag),txtadet(txt.Tag).Text)
        mycoinsdegerbul
    End If
End Sub

this sub is for when user changes a value it stores in kvs.

Any ideas about this ?
 

tufanv

Expert
Licensed User
Longtime User
The focus will go to one of the TextFields.
You can get the current stored value and only call the other sub if it was changed.
is it mandatory that some textfied has to be focused altoguh not selected ?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
You can add a hidden TextField and explicitly set the focus to this field.

It is not possible to disable this behavior.
I tried this , I have added a textfield which is inbivisible and put:
txtinvisible.requestfocus at appstart , but still other textfields getting a focus .
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried this , I have added a textfield which is inbivisible
make it visible but position it outside the screen.
B4X:
textfield.left = 100%x
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Calling RequestFocus in appstart may not always behave as you expect. The focus is requested, but may not be given. I've found in the past that creating a sub and using CallSubDelayed is more consistent.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
   
    CallSubDelayed2(Me,"RequestFocus",tfHidden)

End Sub

Private Sub RequestFocus(tf As TextField)
    tf.RequestFocus
End Sub
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
make it visible but position it outside the screen.
B4X:
textfield.left = 100%x
Calling RequestFocus in appstart may not always behave as you expect. The focus is requested, but may not be given. I've found in the past that creating a sub and using CallSubDelayed is more consistent.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
  
    CallSubDelayed2(Me,"RequestFocus",tfHidden)

End Sub

Private Sub RequestFocus(tf As TextField)
    tf.RequestFocus
End Sub
Both of these are working thanks for help. Previously , with Don's suggestion , I made the textfield visible but its parent was invisible that was the reason it did not work.
Both are just fine ! thanks very much
 
Upvote 0
Top