Android Question Sender Object

Trapachucho

Member
Licensed User
The Sender object repeatedly affects the last of these labels created by code. I try to change the color to the pressed label, but change the color in both.


Code:
   For c = 1 To 4
       lbCl.Initialize("lbName")
       lbCl.TextSize=14
       lbCl.Background=cdWhite
       lbCl.TextColor=Colors.White
       Inf=Prs.Get(c-1)
       lbCl.Text=Inf
       lbCl.Tag=Inf
       lbCl.Gravity=Gravity.CENTER
       Activity.AddView(lbCl,gLeft,gTop,LB.CWidth,LB.CHeight)
       gLeft=gLeft+LB.CWidth
   Next



Public Sub lbName_Click
   Dim LBL As Label
   LBL=Sender
   LBL.Color=Colors.Red
End Sub

I have also tried through the use of an array in Activity Create (lbNames (5)), but the result is the same.

It detects other properties individually and changes them without inconvenience. The same does not happen with color.
 
Last edited:
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png


2. You are reusing the same object.
Code:
For c = 1 To 4
dim lbCl as Label ' !!!
lbCl.Initialize("lbName")
lbCl.TextSize=14
lbCl.Background=cdWhite
lbCl.TextColor=Colors.White
Inf=Prs.Get(c-1)
lbCl.Text=Inf
lbCl.Tag=Inf
lbCl.Gravity=Gravity.CENTER
Activity.AddView(lbCl,gLeft,gTop,LB.CWidth,LB.CHeight)
gLeft=gLeft+LB.CWidth
Next
 
Upvote 0
Thanks for your reply. I apologize for my inexperience in using this forum.

I have tried your suggestion, but the result is the same. However it works with the TextColor Property
 
Last edited:
Upvote 0
but the result is the same
what is the result? What did you expect?

Code:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    For c = 1 To 4
        Dim lbCl As Label
        lbCl.Initialize("lbName")
        lbCl.TextSize=14
        Dim cdWhite As ColorDrawable' note that i create a NEW ColorDrawable for each label.
        cdWhite.Initialize(Colors.White,5)
        lbCl.Background=cdWhite
        lbCl.TextColor=Colors.Blue
        lbCl.Text=Rnd(1,5)
        lbCl.Tag=c
        lbCl.Gravity=Gravity.CENTER
        Activity.AddView(lbCl,0,c*65dip,100dip,60dip)
    Next

End Sub
Public Sub lbName_Click
    Dim LBL As Label = Sender
    LBL.Color=Colors.Red
End Sub

The label color changes on each label i click.
 
Upvote 0
It works perfectly. Thank you so much. My goal was to individually change the color of each label in a group of labels created by code that have the same event name, depending on which one is pressed.

The declaration of a ColorDrawable variable for each iteration did the job.

Thank you.
 
Upvote 0
Back
Top