Wish B4XComboBox: Be able to optionally enter a value instead of selecting one

toby

Well-Known Member
Licensed User
Longtime User
Sometimes a list can't include all items, i.e., mobile phone brands. In that case, users should be able to enter a new item if it's not on the dropdown list.
 

toby

Well-Known Member
Licensed User
Longtime User
I did some research based on the above suggestion and found some code snippet here, I then modified some code block for my need as shown below. When a match is not found, the entered text will be returned, behaving exactly what I was looking for.

B4X:
Sub getItem as string
    Dim strResult As String=""
    Wait For (Dialog.ShowTemplate(Search, "OK", "", "Cancel")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        If Search.SelectedItem.Length>0 Then
            strResult=Search.SelectedItem
        Else
            strResult=Search.SearchField.Text        
        End If
        Log(Search.SearchField.Text)
        Log(Search.SelectedItem)
        LogColor("result=" & strResult, Colors.Blue)
        Search.SearchField.Text=""
        Search.SelectedItem=""
       
        return strResult
    End If
End Sub
 
Top