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:

Code: Copy
        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:

Code: Copy
        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.

B4X: Copy
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
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

Last edited:
Upvote 0
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.

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

Similar Threads

  • Question Question
Android Question B4XComboBox
Replies
2
Views
2K
  • Question Question
Android Question B4XComboBox
Replies
8
Views
3K
Replies
0
Views
3K
Replies
1
Views
3K
Back
Top