B4J Question How to get the SearchField Event in B4XSearchTemplate

Alex Oscar Hedman

Member
Licensed User
Hi there,

I want to get the event "HasFocus" or MouseClicked for the searchfield in this template. How do I initialize the dialog to get it?

Right now, im doing this to initialize the search template

Search template:
    B4XSearchTemplate1.SearchField.Hinttext="Buscar"
    B4XSearchTemplate1.SetItems(list1.items)
                
    B4XSearchTemplate1.Resize(MainForm.Width*0.5,MainForm.Height*0.7)
    Dialog.Title="Usuarios"
    B4XSearchTemplate1.SearchField.Update
    
    Wait For (Dialog.ShowTemplate(B4XSearchTemplate1, "", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
             txt1.TEXT=B4XSearchTemplate1.SelectedItem
    End If

The reason is that I open a self made screen textpad or numpad when I i touch the textfields or b4xfloattextfield

I dont know if I made my point here.

Thanks, Alex
 
Solution
Open XUI Views.b4xlib with 7zip. Extract B4XSearchTemplate from the zip. Rename it and add it to your project as your own template.
This will allow you to add events in the class module.

William Lancee

Well-Known Member
Licensed User
Longtime User
The B4XSearchTemplate (C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries) has this code to monitor
keypresses. You want to change this to handle your own. Make a copy of this B4XLib (which is a zipped file), unzip, rename to a new name.
Then copy the .bas to your project. Add as existing module. Then start experimenting with changing it.
A start would be to use "Private Sub SearchField_FocusChanged (HasFocus As Boolean)"

Wow, beaten again be @Erel, but it is the Olympic season.

B4X:
Private Sub SearchField_TextChanged (Old As String, New As String)
    Update(New, False)
End Sub
 
Upvote 0

Alex Oscar Hedman

Member
Licensed User
Thank you both!, I could do it and its running nicely.

I developed an entire POS system for groceries store and others using b4J and CKVS, b4x is amazing.

Saludos from Argentina
 
Upvote 0
Top