B4J Question [Solved] B4XPages + SMM: Clicking an image for the second time shows first image.

Mark Read

Well-Known Member
Licensed User
Longtime User
I am using the SimpleMediaManager to show images from a webpage as per the example from Erel. I store the name of the image in the tag property of the label. When the label is clicked, a larger version of the image is displayed in a second window. When the images are ready and I click on an image, it is displayed with zoom etc. Then closing the window and clicking a second image, the first image is still shown. I have checked "Main.MainImage" and it has the correct filename. Any help please?

B4XMainPage:
'The calling sub '
Private Sub Label_MouseClicked (EventData As MouseEvent)
    Dim lbl As Label
    lbl=Sender
   
    'main picture is in "cover" not "t_cover"
    Main.MainImage=lbl.Tag
    Main.MainImage=Main.MainImage.Replace("t_cover", "cover")
    Log("opening: " & Main.MainImage)
    'Show the second page with the large image
    B4XPages.ShowPage("LargeImage")
End Sub

DisplayLargeImage:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private Pane1 As B4XView
    Private MediaManager As SimpleMediaManager
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("ImagePane")
    MediaManager.Initialize
    MediaManager.MaxMediaCacheSize = 0
    MediaManager.ClearMedia(Pane1)        'clear old image
    MediaManager.TrimMediaCache            'remove image from cahe
   
    MediaManager.SetMediaWithExtra(Pane1, Main.MainImage, "", CreateMap(MediaManager.REQUEST_ZOOMIMAGEVIEW: True))
    B4XPages.SetTitle(Me, "Large Image")
End Sub
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Here is an example of the problem using these libraries:

1664351441171.png
 

Attachments

  • SMM_Example2_Modified.zip
    188.5 KB · Views: 64
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Found the answer using the B4XPage_Appear. Changed the DisplayLargeImage sub to this:

DisplayLargeImage:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private Pane1 As B4XView
    Private MediaManager As SimpleMediaManager
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    MediaManager.Initialize    '<--- moved from B4XPage_Created
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("ImagePane")
    B4XPages.SetTitle(Me, "Large Image")
End Sub

Sub B4XPage_Appear   '<--- added this to set the image after the page is loaded
    MediaManager.SetMediaWithExtra(Pane1, Main.MainImage, "", CreateMap(MediaManager.REQUEST_ZOOMIMAGEVIEW: True))
End Sub

Just a reminder, set the build configuration with CTRL+B

1664356038067.png
 
Upvote 0
Top