Android Question B4XSearchTemplate: How to skip press OK button.

toby

Well-Known Member
Licensed User
Longtime User
This is about the example accompanying XUI view library

When a single animal name is selected, I want to skip pressing the OK button, and close the dialog right way. How do I modify following code blocks to achieve that, if possible?

thanks


B4X:
    'set the search items
    SearchTemplate.Initialize
    Dim Items As List
    Items.Initialize
    For Each line As String In File.ReadList(File.DirAssets, "colors.txt")
        Dim s() As String = Regex.Split(":", line)
        Dim Name As String = s(0)
        Items.Add(Name)
    Next
    SearchTemplate.SetItems(Items)
    B4XFloatTextField1.NextField = B4XFloatTextField2
    options.Initialize
    options.Options = Array("Cat", "Dog", "Fish", "Crocodile")
    options.AllowMultiSelection = False
    options.MultiSelectionMinimum = 1


Sub btnOptions_Click:
Sub btnOptions_Click
    'wrap it with a timed template
    Dim TimedTemplate As B4XTimedTemplate
    TimedTemplate.Initialize(options)
    TimedTemplate.TimeoutMilliseconds = 10000 'close after 10 seconds (this is the default value)
    
    Wait For (Dialog.ShowTemplate(TimedTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Dialog.Show($"You selected: ${options.SelectedItems.Get(0)}"$, "OK", "", "")
    End If
End Sub
 

toby

Well-Known Member
Licensed User
Longtime User
Further testings confirms that it behaves exactly the way I want after changing the following single line of code
B4X:
options.AllowMultiSelection = False

I don't know what I missed earlier.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
When a single animal name is selected, I want to skip pressing the OK button, and close the dialog right way.
B4X:
Sub btnOptions_Click
    Wait For (Dialog.ShowTemplate(options, "", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Dim MySelection As String =options.SelectedItem
        Log(MySelection)  'displays name of animal you click
    End If
End Sub
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
B4X:
Sub btnOptions_Click
    Wait For (Dialog.ShowTemplate(options, "", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Dim MySelection As String =options.SelectedItem
        Log(MySelection)  'displays name of animal you click
    End If
End Sub

I forgot to mention that I already commented out the 2nd dialog
B4X:
'' Dialog.Show($"You selected: ${options.SelectedItems.Get(0)}"$, "OK", "", "")
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I forgot to mention that I already commented out the 2nd dialog
You need to test the code I posted. I do not think you did.That is for B4XListTemplate indeed. When you click cat it displays cat in the logs without the pressing the OK button. I tested it and it works If not, you need to show your code if mine is not giving you the right answer.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
It works now. I tried it once before posting anything by changing "OK" to "" and it crashed for unknown reason. Now it works.

thanks
 
Upvote 0
Top