Android Question click in Imageview created with code

developer_123

Active Member
Licensed User
Longtime User
I need that when clicking on an image generated within the code (I created it using XUIViewsUtils.CreateB4XImageView), any instruction is executed (for example, changing the value of a variable). The drawback is that when creating the imageview through code, I don't have a pre-written code on the imageview_click routine. How do I achieve this? This is necesary for B4i, B4J and B4A.
 

LucaMs

Expert
Licensed User
Longtime User
I need that when clicking on an image generated within the code (I created it using XUIViewsUtils.CreateB4XImageView), any instruction is executed (for example, changing the value of a variable). The drawback is that when creating the imageview through code, I don't have a pre-written code on the imageview_click routine. How do I achieve this? This is necesary for B4i, B4J and B4A.
B4XImageView does not expose a click event routine. You will need to overlay it with a transparent Pane(l) and create the Click event routine of the latter.
 
Upvote 0

developer_123

Active Member
Licensed User
Longtime User
B4XImageView no expone una rutina de evento de clic. Deberá superponerlo con un Panel transparente (l) y crear la rutina de evento Click de este último.
Lucams, thanks for your response, ok, so now i change the imageView for a button created using code. The question is, how can I modify a variable by clicking on the new buttons created. I need to create 100 buttons, and depending on which button I press, a variable is going to change its state. What I don't know is how to relate a code to modify a variable to the click event of that new button created by code.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can use an ImageView in all three platforms, but you need to treat the Click event differently in B4J.
Can you post a small test project showing the problem ?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Lucams, thanks for your response, ok, so now i change the imageView for a button created using code. The question is, how can I modify a variable by clicking on the new buttons created. I need to create 100 buttons, and depending on which button I press, a variable is going to change its state. What I don't know is how to relate a code to modify a variable to the click event of that new button created by code.
Set the Tag property of each Button and...
B4X:
Private mVar As Int '<--- in Process_Globals

Private Sub Button1_Click
    Dim btn As Button = Sender
    mVar = mVar + btn.Tag
End Sub
 
Upvote 0

developer_123

Active Member
Licensed User
Longtime User
Set the Tag property of each Button and...
B4X:
Private mVar As Int '<--- in Process_Globals

Private Sub Button1_Click
    Dim btn As Button = Sender
    mVar = mVar + btn.Tag
End Sub

Solved!

LucasMs, So much thanks, I had already used the sender variable in a custom list but I didn't know that it could also be used in this way. Finally what I did was create an array of buttons "Dim button(100) As BUTTON" and to differentiate each button I assigned the respective consecutive to the tag in the For routine of creation of the 100 buttons as it is created, as you indicate.
 
Upvote 0

developer_123

Active Member
Licensed User
Longtime User
You can use an ImageView in all three platforms, but you need to treat the Click event differently in B4J.
Can you post a small test project showing the problem ?
Klaus, You're right, the routine that works for imageview click in B4J is "iv_MouseClicked", but this only works with ImageViews created from the designer. Those that are created with code do not respond as indicated by LucasMs. Therefore, I will try to use buttons since these do work and the "Button_Click" event is common to all 3 platforms, later I will add images to each button and I hope that the result will look like I need it.
 
Upvote 0
Top