Android Question Touch event for a button generated by code

ktlua

Member
Licensed User
I find this example:

B4X:
Dim R As Reflector
R.Target=Button1
R.SetOnTouchListener("Button1_Touch")

.......

Sub Button1_Touch(ViewTag As Object, Action As Int, X As Float,Y As Float, Motionevent As Object) As Boolean
   Log("Touched")
End Sub

Button1 is placed by Designer. What will happen if the buttons are generated by code such as:


Dim as Panel
Dim btn as Button
btn.Initialize("Button1")
pnl.AddView(btn,0,0,100dip,100dip)
Dim R As Reflector
R.Target=Button1
R.SetOnTouchListener("Button1_Touch")

I have problem setting the target to Button1.

Please help. Thanks.
 
Top