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
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
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
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.