Events not being called???

Mark Read

Well-Known Member
Licensed User
Longtime User
Can anyone see why the "LargeImage" Click event is not being called in this code?

B4X:
Sub Process_Globals
   Private mBmp As Bitmap
End Sub

Sub Globals
   Dim sv2d As ScrollView2D
   Dim Webview1 As WebView
   Dim width, height As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.AddMenuItem("Fill Screen", "FitToScreen")
   Activity.AddMenuItem("Go back", "GoBack")
End Sub

Sub Activity_Resume
   Activity.Invalidate
End Sub

Sub ShowMainUrl(URL As String)
   Webview1.Initialize("")
   Webview1.LoadUrl(URL)
   Activity.AddView(Webview1, 0, 0, 100%x, 100%y)
   
End Sub

Sub ShowImage(bmp As Bitmap)
   mBmp = bmp
   sv2d.Initialize(mBmp.width, mBmp.height, "LargeImage") 
   sv2d.Panel.SetBackgroundImage(mBmp)
   Activity.AddView(sv2d, 0, 0, 100%x, 100%y)
End Sub

Sub LargeImage_Click
   Activity.OpenMenu
End Sub

Sub GoBack_Click
   If Webview1.IsInitialized Then Webview1.RemoveView
    If sv2d.IsInitialized Then sv2d.RemoveView
   File.Delete(File.DirRootExternal & "/goddess/", Main.ImageFileName)
   Activity.Finish
End Sub

'Trap the back button
Sub Activity_KeyPress (KeyCode As Int) As Boolean                            
    If KeyCode = KeyCodes.KEYCODE_BACK Then
      Activity.OpenMenu
      Return True
   Else
      Return False
    End If 
End Sub

This code is in Activity2 and is called from activity Main with the code

B4X:
CallSubDelayed2(Activity2, "ShowImage", bd)

I have tried a small test program using CAllSubDelayed and the scrollview2d. That worked for click and long click. I am stumped!

Thanks
Mark
 

klaus

Expert
Licensed User
Longtime User
Did you have a look at the ScrollView2 documentation ?
If you had, you would have seen that ScrollView2doesn't support the Click event.
What you could do is add a Panel to the ScrollView set the image to this Panel.Background and use the Click event of this Panel.

Best regards.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Hello Klaus.

I thought that was what I was doing. In sub ShowImage, the background image of a panel is used.

I have the same code in a simpler app, calling a second activity sub from the main activity. This works and gives a click and long click event. Only here it doesn't work???

I am stumped!

Regards
Mark
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In ShowImage you set the background of sv2d.Panel.SetBackgroundImage(mBmp) which is the internal panel of the scrollview.
The events of this panel are cosumed by the ScrollView.
You should define a separate panel with the desired event name and set the image to its background and add it onto the scrollview.

Best regards.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thread closed - solved.

OMG a blind man can see again. Of course you are right Klaus :sign0013:.

I checked my other test app and saw that I was adding an imageview, somehow I missed that here

Modified the ShowImage sub to this:

B4X:
Sub ShowImage(bmp As Bitmap)
   iv.Initialize("LargeImage")
   mBmp = bmp
   iv.Bitmap=mBmp
   sv2d.Initialize(mBmp.width, mBmp.height, "")
   sv2d.Panel.AddView(iv,0,0,mBmp.width, mBmp.height)
   Activity.AddView(sv2d, 0, 0, 100%x, 100%y)
End Sub

Now it works perfectly! Thanks.
 
Upvote 0
Top