Hi, thanks to @Mahares I created the activity below, is there a method to delete the selected lbl with a long_click? or if there isn't the last lbl with button? Thanks!!!
Here is a complete project where you can delete the last label either by long click of the label itself or a button. It deletes from the last button up every time you click the button or long click the label itself
This solution and changes are to remove the last inserted label with the long click.
Your project by the way crashes. You need to comment all these Label.visible lines
' Label1.Visible=False
' Label2.Visible=False
' Label3.Visible=False
' Label4.Visible=False
' Label5.Visible=False
' .....In between too
' Label20.Visible=False
' Label21.Visible=False
B4X:
Private x, i As Int 'needs added to Globals
B4X:
Private Sub Button1_Click
Dim w =200dip, h=50dip As Float
lbl(i).Initialize("lbl")
Activity.AddView(lbl(i), 0,i*60dip+200dip, w, h)
lbl(i).Text= a
lbl(i).TextSize = 20
ColorLabel(lbl(i))
x=i
i=i+1
If i=n Then Button1.Enabled =False
End Sub
B4X:
Private Sub lbl_LongClick
Activity.RemoveViewAt(x+2) 'the 2 is because the labels come after Panel1 and Button1 in the activity
i=i-1
End Sub
If you have trouble I can post your project corrected
If you want to remove more than 1 label but starting from the bottom one on up, this will work. For random label removal, you will need to tweak it. I did not have a chance to look further. In that case put the corrected project and ask the members to help you for more tweaking
B4X:
Private Sub Button1_Click
Dim w =200dip, h=50dip As Float
lbl(i).Initialize("lbl")
Activity.AddView(lbl(i), 0,i*60dip+200dip, w, h)
lbl(i).Text= a
lbl(i).TextSize = 20
ColorLabel(lbl(i))
lbl(i).Tag =i 'add this line
x=i
i=i+1
If i=n Then Button1.Enabled =False
End Sub
B4X:
Private Sub lbl_LongClick
Dim l As Label=Sender
Activity.RemoveViewAt(l.tag+2) 'the 2 is because the labels come after Panel1 and Button1 in the activity
End Sub
Here is a complete project where you can delete the last label either by long click of the label itself or a button. It deletes from the last button up every time you click the button or long click the label itself