Android Question How to preselect a B4XListTemplate item

toby

Active Member
Licensed User
When the dialog appears, I want to highlight the second item with different text color and/or background color, Unfortunately the following code doesn't work for me. Could someone kindly show me how to achieve that, please?

Unable to highlight the preselected item:
    Dim options As B4XListTemplate
    options.Initialize
    options.Options = Array("Cat", "Dog", "Fish", "Crocodile")
    
    options.SelectedItem="Dog" '<==preselect second item
    options.SelectionColor=xui.Color_Magenta 'show it in different color
    
    Wait For (Dialog.ShowTemplate(options, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dialog.Show($"You selected: ${options.SelectedItem}"$, "OK", "", "")
    End If
 

toby

Active Member
Licensed User
I'm hoping for a simple solution without the need of modifying the library source code.
 
Upvote 0

Mahares

Expert
Licensed User
Could someone kindly show me how to achieve that, please?
This will take care of you Toby, without changing library
B4X:
Dim options As B4XListTemplate
    options.Initialize
    options.Options = Array("Cat", "Dog", "Fish", "Crocodile")   
    Dim rs As ResumableSub =Dialog.ShowTemplate(options, "OK", "", "CANCEL")
    options.SelectedItem = options.Options.Get(1)
    options.SelectionColor=xui.Color_Magenta
    options.CustomListView1.GetPanel(1).Color = options.SelectionColor   
    wait for (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dialog.Show($"You selected: ${options.SelectedItem}"$, "OK", "", "")
    End If
 
Upvote 1
Top