Android Question [SOLVED] Which of Four Panels in One Row of an xCLV is Clicked

John Naylor

Active Member
Licensed User
Longtime User
I may be missing something here but....

Using SMM 1.07 and the SMM example 2 which displays images in 4 columns I add

B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    
    Log ("Index = " & Index)
    Log ("Value = " & Value)
    
End Sub

When I run the demo and tap on each picture in the first and second rows I get the following -

For each item on the first row

Index = 0
Value = [IndexOfFirstImage=1, IsInitialized=true]

and each value on the second row is

Index = 1
Value = [IndexOfFirstImage=5, IsInitialized=true]

I understand why IndexOfFirstImage changes from 1 to 5 but how can I know which image on the row of 4 has actually been clicked?

Thanks for reading!
 

John Naylor

Active Member
Licensed User
Longtime User
The question is not really related to SMM, however here is the answer:
1. Set the event name of the 4 panels to Panel.

2. Add to VisibleRangeChanged:
B4X:
pnl.GetView(x).Tag = data.IndexOfFirstImage + x 'inside the loop

3.
B4X:
Private Sub Panel_Click
    Log(Sender.As(B4XView).Tag)
End Sub
Hmmm - I've made that change however the log is returning null. Both in my code and the example.

B4X:
Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = CustomListView1.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("Panel")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Dim data As MyImageData = item.Value
        'Create the item layout
        pnl.LoadLayout("item")
        For x = 0 To 3
            pnl.GetView(x).Tag = data.IndexOfFirstImage + x 'inside the loop
            pnl.GetView(x).GetView(1).Text = data.IndexOfFirstImage + x
            MediaManager.SetMedia(pnl.GetView(x).GetView(0), $"https://picsum.photos/id/${data.IndexOfFirstImage + x}/200/300.jpg"$)
        Next
    Next
    'The purpose of this call is to find panels that are no longer in the views tree and cancel any ongoing request that is no longer relevant.
    'It also happens automatically from time to time but in this case, as many requests are sent frequently, it is better to force it to trim the cache.
    'Note that you need to add HU2_PUBLIC to the build configuration.
    MediaManager.TrimMediaCache
End Sub

Private Sub Panel_Click
    Log(Sender.As(B4XView).Tag)
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I've made that change however the log is returning null. Both in my code and the example.
You probably did not set the correct event to the 4 required panels.
These 4 panels should be: Panel1, Panel2, Panel3, Panel4. All 4 should have Panel as the event name, Do not mess with pnlImage1, 2, 3, 4, etc.
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
This works and shows the relevant tags on the child panels but I still don't know which one was clicked...

B4X:
Private Sub Panel_Click
    Log(Sender.As(B4XView).GetView(0).Tag)
    Log(Sender.As(B4XView).GetView(1).Tag)
    Log(Sender.As(B4XView).GetView(2).Tag)
    Log(Sender.As(B4XView).GetView(3).Tag)
End Sub
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
Ahhh sorry - It's late here - Yes indeed I needed to set the event name in the designer for each of the image views.

For some reason I thought I was setting it at Line 4 above but that's my daft mistake.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
es indeed I needed to set the event name in the designer for each of the image views.
Glad you got it sorted out. It might be a good idea to edit your thread title, because your problem was not related to SMM, but rather to xClv. Perhaps as an example, something like: Which of Four Panels in One Row of an xCLV is Clicked,
or whatever term you use for clv
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
Glad you got it sorted out. It might be a good idea to edit your thread title, because your problem was not related to SMM, but rather to xClv. Perhaps as an example, something like: Which of Four Panels in One Row of an xCLV is Clicked,
or whatever term you use for clv
Great idea - Will do.
 
Upvote 0
Top