Handling Button pressed and other View events in a class?

raytronixsystems

Active Member
Licensed User
Longtime User
I have used the reflection library to capture clicks from ImageViews in classes. I was wondering if it is possible to handle events from Buttons using reflection as well in a class. Is it the same?
I am specifically looking for click, button pressed, unpressed (up) and longpress events for buttons and other types of ImageViews. I need to detect all events in order to change the graphic for the pressed and unpressed conditions. At the moment, I am using an Imageview to simulate a button but not sure how to detect whether the button is pressed to change out the graphic to show the user that the :button: was pressed.
Partial example below:

B4X:
Dim rHomeBtn As Reflector                                                    ' Set up Click handler
   rHomeBtn.Target = HomeBtn  ' HomeBtn was previously declared as an                         ImageView and passed to the class                                                   '
   rHomeBtn.SetOnClickListener("HomeBtn_OnClick")   

''...
'
   ' HomeBtn_OnClick will handle the Click Event for the Home and HomeIcon Buttons
   '
Public Sub HomeBtn_OnClick(ViewTag As Object)
   '
   GenClickSound                                                ' make some noise!
'''   Msgbox("HomeBtn click has been trapped by class", "HomeBtn")
   Show (dbc.DASHBOARD_BUTTON_HOME)                                 ' Show the Main Menu
'''   Show(dbc.DASHBOARD_BUTTON1)
   '
   ' End of subroutine HomeBtn_OnClick
   '   
End Sub
'
'
All I want to do is replace the ImageViews in my code with Buttons. All code written so far does not use the designer. All views are created at runtime.

Any suggestions, examples would be greatly appreciated.

Thx In Advance,
Ray
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…