Hello!
I was reading on here that you could process Click Events inside a class just as
you could in your Activity. I'm trying to move as much code out of Main into my Classes I I can and ran into a problem processing a simple click by my class.
I am not sure if click events for Views created by the designer can be handled by a class. I tried tonight and had no luck.
I created a Panel with the Designer and put one ImageView on it. Normally I wouldDim the ImageView in Global Subs, write a click event in Main and off I am.
Here is a sample of what my non-working code class looks like:
I have tried putting the "etc.Initialize" code on either side of the
LoadLayout statement and get no compile or run time error, but when I
press on betaImageView1 on the Panel it never executes the "click" event
in the class. The code was working fine outside of the class until I moved it to the test class.
I put the AHdashboard code inside of a class and all is working fine but would like to move my App click events outside of Main to make my class as reusable as possible. I had just created a simple welcome screen with the designer and once the user pressed on the imageview it would invoke the Dashboard "Main Menu". I plan on replacing the Welcome screen with a Splash Screen I had coded a while back.
Any idea what is going on? I think the problem is related to the fact that the designer has generated it's own java code that is doing it's own initialization.
I have not tried creating my own Panel at run time and placing a button or imageview on the panel and handling the click events in my class. Something to try perhaps? There must be a way of handling Designer Views in a class. Any suggestions or guidance would be welcome.
Regards,
Ray
I was reading on here that you could process Click Events inside a class just as
you could in your Activity. I'm trying to move as much code out of Main into my Classes I I can and ran into a problem processing a simple click by my class.
I am not sure if click events for Views created by the designer can be handled by a class. I tried tonight and had no luck.
I created a Panel with the Designer and put one ImageView on it. Normally I wouldDim the ImageView in Global Subs, write a click event in Main and off I am.
Here is a sample of what my non-working code class looks like:
B4X:
' module EventTestClass Code:
'Class module
'
Sub Class_Globals
'
' this was in main Global Subs:
'
Dim BetaImageView1 As ImageView ' the ImageView...
'
End Sub
'Initializes the object. You can add parameters to this method if needed.
'
Public Sub Initialize
'
BetaImageView1.Initialize("BetaImageView1")
'
End Sub
Public Sub BetaImageView1_Click
'
ToastMessageShow("Hello from Class Click!", True)
CallSub (Main,"ShowDashboard") 'Display '
'
'End of subroutine BetaImageView_Click
'
End Sub
'
'------------------------------------------------------------------
' module Activity Main Code:
Sub Activity_Create(FirstTime As Boolean)
Dim etc As EventTestClass ' For our event test class
'etc.Initialize ' tried here...
Activity.LoadLayout("1") 'l ' '
etc.Initialize ' and tried here too
'
'End of subroutine Activity_Create
'
End Sub
I have tried putting the "etc.Initialize" code on either side of the
LoadLayout statement and get no compile or run time error, but when I
press on betaImageView1 on the Panel it never executes the "click" event
in the class. The code was working fine outside of the class until I moved it to the test class.
I put the AHdashboard code inside of a class and all is working fine but would like to move my App click events outside of Main to make my class as reusable as possible. I had just created a simple welcome screen with the designer and once the user pressed on the imageview it would invoke the Dashboard "Main Menu". I plan on replacing the Welcome screen with a Splash Screen I had coded a while back.
Any idea what is going on? I think the problem is related to the fact that the designer has generated it's own java code that is doing it's own initialization.
I have not tried creating my own Panel at run time and placing a button or imageview on the panel and handling the click events in my class. Something to try perhaps? There must be a way of handling Designer Views in a class. Any suggestions or guidance would be welcome.
Regards,
Ray