Click on an ImageView into panel

FMFREAK

Member
Licensed User
Longtime User
I have this code:

B4X:
   For i = 0 To Cursor.RowCount -1
      Dim Height, Height2 As Float
      Dim lblAgnDatum, lblAgnVak,lblAgnId As Label
      Dim datumveld As String
      Dim imgAgnDelete As ImageView
      lblAgnDatum.Initialize("")
      lblAgnVak.Initialize("")
      lblAgnId.Initialize("")
      imgAgnDelete.Initialize("")
      imgAgnDelete.Bitmap = LoadBitmap(File.DirAssets,"delete.png")
      Agendaoverzicht.Panel.Height=Agendaoverzicht.Height
      Agendaoverzicht.Panel.Color = Colors.Transparent
      Cursor.Position = i
      DateTime.DateFormat="dd/MM/yyyy"
      datumveld=DateTime.Date(Cursor.GetLong("datum"))
      lblAgnDatum.Text=datumveld
      lblAgnVak.Text=Cursor.GetString("vak")
      lblAgnVak.TextColor = Colors.Black
      lblAgnVak.TextSize = 12
      lblAgnDatum.TextColor = Colors.Black
      lblAgnDatum.TextSize = 15
      lblAgnId.Text=Cursor.GetInt("id")
      imgAgnDelete.Tag = Cursor.GetInt("id")
      Agendaoverzicht.Panel.AddView(lblAgnDatum, 5dip, 5dip + TotalHeight, Agendaoverzicht.Width, -2)
      Agendaoverzicht.Panel.AddView(lblAgnVak, 5dip, 25dip + TotalHeight, Agendaoverzicht.Width, -2)
      Agendaoverzicht.Panel.AddView(imgAgnDelete, 250dip, 8dip + TotalHeight, 20, 20)
      DoEvents
      Reflect.Target=lblAgnDatum
        Height=Reflect.RunMethod("getHeight")
      DoEvents
      Reflect.Target=lblAgnVak
      Height2=Reflect.RunMethod("getHeight")
      TotalHeight=TotalHeight+Height+Height2
      Agendaoverzicht.Panel.Height=TotalHeight
   Next

How can I go to an Sub imgAgnDelete_Click with this code. The idea is to delete a row with an id from the database when someone clicks on the image.
 

derez

Expert
Licensed User
Longtime User
I'm not sure I understand what you want, but if you want to have an active event for imgAgnDelete_Click, then you have to define the event, instead of
B4X:
imgAgnDelete.Initialize("")
use
B4X:
imgAgnDelete.Initialize("imgAgnDelete")
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As derez already answered, you need:
B4X:
imgAgnDelete.Initialize("imgAngDelete")
Where 'imgAngDelete' is the name of the event.

Then, in the same Activity you need the Click event routine:
B4X:
Sub imgAngDelete_Click
  Dim Send As ImageView
  Dim id As Int
  Send = Sender  ' gets the View that raised the Click event
  id = Send.Tag  ' id = Tag of the ImageView that raised the Click event
  ' the code depending on what you want to do
End Sub
Best regards.
 
Upvote 0
Top