Bug? ScrollView in a Class doesn't get last item wrong Sender object

klaus

Expert
Licensed User
Longtime User
In a project for a ComboBox class I have a problem when selecting the last item in a ScrollView.
The ScrollView Panel is filled only with Labels having a common lblItem_Click event and the index as the Tag property.
When I click on the last item, the lblItem_Click event is raised but the Sender object is not the last item but the previous one that was selected.
It works OK for all others.

Attached a test project.
 

Attachments

  • ClassComboBox.zip
    10.6 KB · Views: 229

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is here:
B4X:
For i = 0 To lstComboBox.Size - 1
     Dim lbl As Label
     
     lbl.Initialize("lblItem")
     itemWidth = lblComboBox.Width - 2 * cBoarderWidth
     scvComboBox.Panel.AddView(lbl, itemLeft, i * itemHeight, itemWidth, itemHeight_1)
     lbl.Gravity = Gravity.CENTER_VERTICAL
     lbl.Color = cItemColor
     SetPadding(lbl, 0.5 * cTextSize * 100dip / 100, 1dip, 0.5 * cTextSize * 100dip / 100, 1dip)
     lbl.Text = lstComboBox.Get(i)
     lbl.Tag = i
     lbl.TextColor = cTextColor
     lbl.Color = cItemColor
     lbl.TextSize = cTextSize
   Next
   Dim lbl As Label 'add this line to fix it
   If cSelectedIndex >= 0 Then
     lbl = scvComboBox.Panel.GetView(cSelectedIndex)
     lbl.Color = cSelectedItemColor
     lbl.TextColor = cSelectedTextColor
   End If

This is indeed a bug. Related to the reuse of the lbl variable. You should redeclare lbl to fix it (see the line above).

It will be fixed in the next version.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…