Android Question How to "get" B4XComboBox

swabygw

Active Member
Licensed User
Longtime User
I have a ScrollView with several B4XComboBox objects on it. I'd like to loop through them and get the selected text. I'm trying:

B4X:
        Dim obj As Object = ScrollView1.Panel.GetView((i*5)+4)
        Dim cmb As B4XComboBox = obj
        Dim X,Y As String      
        X = cmb.SelectedItem
        Y = cmb.cmbBox.SelectedItem

Both cmb.SelectedItem and cmb.cmbBox.SelectedItem cause errors. I'm think that the first two lines of the code (obj and cmb) are incorrect somehow. Any ideas?

fyi - here's how the comboboxes are initially created:

B4X:
        Dim cmb As B4XComboBox
        cmb.Initialize("cmb", Null)
        cmb.Tag = "cmb_" & i
        cmb.cmbBox.Initialize("cmbBox")
        cmb.cmbBox.Tag = "cmbBox_" & i
        cmb.cmbBox.TextSize = 12
        cmb.cmbBox.Add("None")
        cmb.cmbBox.Add("Test")
        cmb.SelectedIndex = 0
        ScrollView1.Panel.AddView(cmb.cmbBox, 65%x, ItemHeight * i, ScrollView1.Width, ItemHeight - 1dip)
 
Last edited:
Solution
The B4XCombox has been added to a layout , which is then loaded to the scrollview as needed.

I have commented out the unneeded code.


These 2 threads are relevant if you have not already read them.

swabygw

Active Member
Licensed User
Longtime User
B4X:
Dim cmb As B4XComboBox = ScrollView1.Panel.GetView((i*5)+4).Tag
Thanks for replying. That works for getting the Tag. Both lines 4 & 5 of the sample code in original posting still fail, however, for getting the SelectedItem. Or are you recommending that I update the Tag(s) on the SelectedIndexChanged event?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
The B4XCombox has been added to a layout , which is then loaded to the scrollview as needed.

I have commented out the unneeded code.


These 2 threads are relevant if you have not already read them.

 

Attachments

  • ComboBoxExample 2.zip
    9.9 KB · Views: 65
Last edited:
Upvote 0
Solution

swabygw

Active Member
Licensed User
Longtime User
Well, that was it. Excellent example, thanks. I think I missed those articles because I stopped using b4x for several years (and just started updating an old app this week).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…