B4J Question [B4XTable] Set Focus To Search Field On StartUp

B4XDev

Member
Licensed User
I'd like to start the cursor in the B4XTable search field when the app starts.

How do I request focus for it?

This doesn't work:
Attempt to Request Focus for B4XTable Search Field:
tbl_Activity.SearchField.TextField.RequestFocus

Thank you!
 

Attachments

  • B4XTable-Searchfield-Focus.zip
    9.5 KB · Views: 26

Alexander Stolte

Expert
Licensed User
Longtime User
This code B4XTable1.SearchField.RequestFocusAndShowKeyboard works wonderfully, the B4XTable needs a short moment until it is finished building and only then can you set the focus on the search field.

Set a Sleep(250) to solve your problem.
B4X:
    B4XTable1.SetData(StateData)
    Sleep(250)
    RequestSearchFieldFocus
 
Upvote 0

B4XDev

Member
Licensed User
This code B4XTable1.SearchField.RequestFocusAndShowKeyboard works wonderfully, the B4XTable needs a short moment until it is finished building and only then can you set the focus on the search field.

Set a Sleep(250) to solve your problem.
B4X:
    B4XTable1.SetData(StateData)
    Sleep(250)
    RequestSearchFieldFocus

Thank you for the very simple solution! I thought the CallSubDelayed() was doing that, but apparently not!

I wonder if B4XTable could probably have a _Ready() function. In fact, anything that might take its own sweet time to get ready should probably have one.

That way, we don't have to resort to a kludge of Sleep(), which might be inconsistent between systems in timing. But I guess a few milliseconds will never hurt anyone.

What is best-practice in this case? Would Wait for() be useful here, maybe on the SetData() call?

(Just trying to wrap my head around the B4X paradigm so I don't get stuck like this in the future.)
 
Upvote 0
Top