Android Question changing corresponding objext in object-array

gruizelgruis

Member
Licensed User
I modified the "AHViewPager" example a bit and added a scrollview.
In the,
"Sub CreatePanel(PanelType As Int, Title As String) As Panel" sub, I added the folowing

within the select case structure

B4X:
Case TYPE_SCROLLVIEW
            Dim SV As ScrollView
            SV.Initialize(0)
            Dim pnl As Panel
            pnl = SV.Panel
        
        
            For i = 0 To 29
                Dim Lbl_Count As Label
                Dim Lbl_Name As Label
                Dim Cmd_Plus As Button
                Dim Cmd_Min As Button

            
                Cmd_Plus.Initialize("Cmd_plus")
                Cmd_Min.Initialize("Cmd_Min")
                Lbl_Count.Initialize("")
                Lbl_Name.Initialize("")
            
                Cmd_Plus.Text = "+"
                Cmd_Min.Text ="--"
            
                Lbl_Name.Text = i & "Omschrijving"
                Lbl_Name.TextSize = 32
                Lbl_Count.TextSize = 32
                Lbl_Count.Text = "+"
                pnl.AddView(Lbl_Count, 0, height * (i - 1), 50dip, height)
                pnl.AddView(Lbl_Name, 55dip, height * (i - 1), 100%x-75dip, height)
                pnl.AddView(Cmd_Plus, 100%x-80dip, height*(i-1),15%x, height)
                pnl.AddView(Cmd_Min, 100%x-60dip, height*(i-1),15%x, height-10%y)
                Cmd_Min.Visible = False '// only gets shown when count > 0
            Next
            pnl.height = i * height
            pan.AddView(SV, 0, 0, FILL_PARENT, FILL_PARENT)
         ......

I know how to catch the "Cmd_add_click" event using reflexion

B4X:
Sub Cmd_Plus_click()
Dim Btn As Button

Btn = Sender

Msgbox (Btn.Text ,"klik")
....
How can I set the correct Lbl_Count.text after the cmd_plus_click event.
How do I get the correct handle on the correct label. ?

Please advice
 
Last edited:

stevel05

Expert
Licensed User
There are a few ways you could do this, probably the simplest would be to add a reference to the Label in the Buttons Tag:

B4X:
Cmd_Plus.Tag =  Lbl_Count
Cmd_Min.Tag = Lbl_Count
Then

B4X:
Sub Cmd_Plus_click()
Dim Btn As Button

Btn = Sender

Dim Lbl As Label = Btn.Tag
Lbl.Text = Lbl.Text + 1

Msgbox (Btn.Text ,"klik")
 
Top