Android Question B4A Search Template - how to control textChanged Event on the searchField

jcbs

New Member
Hello everyone,

this is my first post after a little time working with b4a and surfing the forums. I would like to thanks everyone in advance for all the help given in the forum and say that this is a great community. After that, going straight to the issue.

I would like to know if it is possible to control the text changes on the SearchField within a B4XSearchTemplate. I am trying to get the SearchField within the B4XSearchTemplate object and setting a TextChanged event (sub) for it. I am pretty sure that I am doing something wrong, since it does not call the event sub.

I don't understand how to set events programatically so if someone could point me to the right documentation or tutorials I'd really appreciate it.

This is my code, I highlihted the lines that should (in my head) do the work. Also I attached the whole project, in case someone wants to try and correct it.


textoBuscar:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Dialog As B4XDialog
    Private XUI As XUI
    Private btnSearch As SwiftButton
    Private SearchTemplate As B4XSearchTemplate
    Private Base As B4XView
    Private textoBuscar As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    Base = Activity
    Dialog.Initialize (Base)
    Dialog.Title = "Frutas de estación"
    'set the search items
    SearchTemplate.Initialize
    Dim Items As List
    Items.Initialize
    Items.AddAll(Array As String("Banana", "Pera", "Manzana" ,"Uva", "Naranja", "Melon", "Kiwwi", "Damasco", "Sandia"))
    Items.Sort(True)
    SearchTemplate.SetItems(Items)
End Sub

Sub btnSearch_Click
    SearchTemplate.SearchField.HintText = "Escriba la fruta ...."   
    textoBuscar = SearchTemplate.SearchField.TextField
    'Refresca el Template
    SearchTemplate.SearchField.Update
    Wait For (Dialog.ShowTemplate(SearchTemplate, "", "", "Salir")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        btnSearch.xLBL.Text = SearchTemplate.SelectedItem
    End If
End Sub

Sub textoBuscar_TextChanged
    Log(textoBuscar.Text)
End Sub


Thanks so much
 

Attachments

  • textoBuscar.zip
    9.6 KB · Views: 165

Mahares

Expert
Licensed User
Longtime User
I would like to know if it is possible to control the text changes on the SearchField within a B4XSearchTemplate.
You full project code should be:
B4X:
Sub Globals
    Private Dialog As B4XDialog
    Private XUI As XUI
    Private btnSearch As SwiftButton
    Private SearchTemplate As B4XSearchTemplate
    Private Base As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    Base = Activity
    Dialog.Initialize (Base)
    Dialog.Title = "Frutas de estación"
    SearchTemplate.Initialize
    Dim Items As List
    Items.Initialize
    Items.AddAll(Array As String("Banana", "Pera", "Manzana" ,"Uva", "Naranja", "Melon", "Kiwwi", "Damasco", "Sandia"))
    Items.Sort(True)
    SearchTemplate.SetItems(Items)
    SearchTemplate.SearchField.HintText = "Escriba la fruta ...."
    SearchTemplate.SearchField.Update
End Sub

Sub btnSearch_Click
    Wait For (Dialog.ShowTemplate(SearchTemplate, "", "", "Salir")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        btnSearch.xLBL.Text = SearchTemplate.SelectedItem 
        Log(SearchTemplate.SearchField.Text)  'displays the search string typed in search box
    End If
End Sub
you do not need Sub textoBuscar_TextChanged because the SearchTemplate is already based on a B4XFloatTextField with TextChanged event
 
Upvote 0

jcbs

New Member
Thanks for the early response! How could I control that event? or customize the code it triggers?

Is there any documentation/tutorials about how to set custom events I could look at?
 
Upvote 0

jcbs

New Member
I still haven´t found the solution to this issue.
Let me rephrase the problem.

Is there any way to program the textChanged event on the SearchField withnig a B4XSearchTemplate?

Thanks in advanced
 
Upvote 0

jcbs

New Member
Thanks so much for the response. I am trying to modify it, and to modify my code so the object types match accordingly.
I still have to learn much about casting, custom views and much more stuff but I really appreciate the help.
 
Upvote 0
Top