Android Question [solved] B4XImageView how to use Click-Event?

DonManfred

Expert
Licensed User
Longtime User
Hello,

i have an B4XImageView because of its Features to Fit the image.

But i do need the Click-Event. How to i set a eventhandler for a B4XImageView?
 
Solution
I place B4XImageView inside a Panel, I then use the panel click event, the click goes right through the image directly to the panel.
it also works without a special inner panel.

B4X:
            Dim pnl As B4XView = xui.CreatePanel("titel")
            pnl.SetLayoutAnimated(0,0,0,scvMain.AsView.Width,itemheight)
            pnl.LoadLayout("PosItem") ' PosItem-Layout only contains the b4ximageview btw
            pnl.Tag = aktart.Get("bildname7")
            scvMain.Add(pnl,pnl.Tag)
i now use the tag from the Panel created by xui.CreatePanel

B4X:
Private Sub titel_Click  'to create a pseudo raise click event of B4XImageView1 by clicking the panel that holds the img
    Log($"titel_Click()"$)
    Dim index As Int =...

Marvel

Active Member
Licensed User
Why not out the B4XImageView inside a panel before adding it to the CLV so you can capture the panel touch event. That's what I do
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I place B4XImageView inside a Panel, I then use the panel click event, the click goes right through the image directly to the panel.
it also works without a special inner panel.

B4X:
            Dim pnl As B4XView = xui.CreatePanel("titel")
            pnl.SetLayoutAnimated(0,0,0,scvMain.AsView.Width,itemheight)
            pnl.LoadLayout("PosItem") ' PosItem-Layout only contains the b4ximageview btw
            pnl.Tag = aktart.Get("bildname7")
            scvMain.Add(pnl,pnl.Tag)
i now use the tag from the Panel created by xui.CreatePanel

B4X:
Private Sub titel_Click  'to create a pseudo raise click event of B4XImageView1 by clicking the panel that holds the img
    Log($"titel_Click()"$)
    Dim index As Int = scvMain.GetItemFromView(Sender)
    Dim pnl As B4XView = scvMain.GetPanel(index)
    ' I now use the tag set on the Panel to work further
end sub

Thank you all for your answers! ;-)
 
Last edited:
Upvote 2
Solution

Mahares

Expert
Licensed User
Longtime User
Sine you are using the panel click event titel_Click without the need for the inner panel , you can replace these 2 lines:
B4X:
Dim index As Int = scvMain.GetItemFromView(Sender)
Dim pnl As B4XView = scvMain.GetPanel(index)
with this one line:
B4X:
Dim pnl As B4XView = Sender   'or Sender.As(B4XView)
 
Upvote 0
Top