iOS Question CustomListView, Single layout used multiple time with different event names.

Rory Mapstone

Member
Licensed User
Longtime User
Good day,

Is it possible to have one layout with a CustomListView which is used multiple times in a code module but to change the event name handler to be unique to be able to identify which CustomListView fired the event?

Thanks
 

Rory Mapstone

Member
Licensed User
Longtime User
I have the following code, loFeedDetail has the custom list view with the name and event name CLV with is added with the designer.

B4X:
pnlAccepted.LoadLayout("loFeedDetail")
pnlMaybe.LoadLayout("loFeedDetail")
pnlDeclined.LoadLayout("loFeedDetail")

I have one code module with a tab bar controller with three pages (3 tabs, accepted - muted -declined), each of them load the respective panel above.

The old custom list view library allowed you to initialize the custom list view with different event names, but the CLV had to be added to the view with code.
B4X:
clv.Initialize(Me, "clv_eventname", Width)
page.RootPanel.AddView(clv.AsView, 0, 0, Width, height)

I don't understand how to use the tag as you say, it would be the same issue with the tag. Would you have to do something as follows?

B4X:
pnlAccepted.Initialize("Accepted")
pnlMaybe.Initialize("Maybe")
pnlDeclined.Initialize("Declined")

pnlAccepted.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "accepted"
pnlMaybe.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "maybe"
pnlDeclined.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "declined"

This would just overwrite the tag name.

The easy way to solve this is to save the same layout with three different names(e.g. loFeedDetailAccepted, loFeedDetailMabye, loFeedDetailDeclined) and change the event names respectively that way, but this feels messy. Would this be the only way?

B4X:
pnlAccepted.LoadLayout("loFeedDetailAccepted")
pnlMaybe.LoadLayout("loFeedDetailMabye")
pnlDeclined.LoadLayout("loFeedDetailDeclined")

Regards
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Rory Mapstone

Member
Licensed User
Longtime User
It will not. The 'clv' variable will point to the last view loaded named clv. So it will point to the correct CustomListView instance each time.

Ok thank you, based on this I have tried the following:

B4X:
pnlHeaderAccepted.LoadLayout("loFeedDetail")
lblFeedDetailHeader.Text = Global.THD_Selected.name
clv_Accepted.Initialize(Me, "clv_Accepted")
clv_Accepted = clv_feed
pnlHeaderMaybe.LoadLayout("loFeedDetail")
lblFeedDetailHeader.Text = Global.THD_Selected.name
clv_Maybe.Initialize(Me, "clv_Maybe")
clv_Maybe = clv_feed
pnlHeaderDeclined.LoadLayout("loFeedDetail")
lblFeedDetailHeader.Text = Global.THD_Selected.name
clv_Declined.Initialize(Me, "clv_Declined")
clv_Declined = clv_feed

After adding some list items to the respective views the onclick events still calls the event_name that is defined in the layout which is "clv_feed" for all three customelistviews and not clv_Accepeted, clv_Maybem clv_Declined.

B4X:
Sub clv_feed_ItemClick (Index As Int, Value As Object)
'This gets called.   
End Sub

B4X:
Sub clv_Accepted_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub

Sub clv_Declined_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub

Sub clv_Maybe_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub


Am I initializing the custom list views incorrectly? I would like to identify which custom list view contained the clicked item.


Thanks
 
Upvote 0

Rory Mapstone

Member
Licensed User
Longtime User
Thanks Erel, that is what I am doing but I need to change the event_name. I don't want to have 3 of the same layouts with different names.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
   
    '*** Page Layout ***'
    Dim pageAccepted As Page
    Dim pageMaybe As Page
    Dim pageDeclined As Page
   
    Dim pnlHeaderAccepted As Panel
    Dim pnlHeaderMaybe As Panel
    Dim pnlHeaderDeclined As Panel
   
    Dim clv_Accepted As CustomListView
    Dim clv_Maybe As CustomListView
    Dim clv_Declined As CustomListView
    Public parentPage As Page
    Private lblFeedDetailHeader As Label
    Private cf As commonFunctions
    'This clv_feed comes from the layout loFeedDetail
    Private clv_feed As CustomListView
End Sub

Sub Show
    '** Header Panels
    pnlHeaderAccepted.Initialize("")
    pnlHeaderMaybe.Initialize("")
    pnlHeaderDeclined.Initialize("")
   
    'Reuse the same layout but populate the CLV with different data
    pnlHeaderAccepted.LoadLayout("loFeedDetail")
    lblFeedDetailHeader.Text = Global.THD_Selected.name
    clv_Accepted.Initialize(Me, "clv_Accepted")
    clv_Accepted = clv_feed
    pnlHeaderMaybe.LoadLayout("loFeedDetail")
    lblFeedDetailHeader.Text = Global.THD_Selected.name
    clv_Maybe.Initialize(Me, "clv_Maybe")
    clv_Maybe = clv_feed
    pnlHeaderDeclined.LoadLayout("loFeedDetail")
    lblFeedDetailHeader.Text = Global.THD_Selected.name
    clv_Declined.Initialize(Me, "clv_Declined")
    clv_Declined = clv_feed

    pageAccepted.Initialize("pageAccepted")
    pageMaybe.Initialize("pageMaybe")
    pageDeclined.Initialize("pageDeclined")
   
    Global.SetPageTitle(pageAccepted, "Accepted")
    Global.SetPageTitle(pageMaybe, "Maybe")
    Global.SetPageTitle(pageDeclined, "Declined")   
   
   
    ' ** Add layout to the Pages
    pageAccepted.RootPanel.AddView(pnlHeaderAccepted,0,0,Global.PageWidth, Global.PageHeight)       
    pageMaybe.RootPanel.AddView(pnlHeaderMaybe,0,0,Global.PageWidth, Global.PageHeight)
    pageDeclined.RootPanel.AddView(pnlHeaderDeclined,0,0,Global.PageWidth, Global.PageHeight)
   

   
    If Global.TabController.IsInitialized = False Then
        Global.AddTabBarController("tc", App, Array(pageAccepted, pageMaybe, pageDeclined), 0)   
    Else
        Global.SetTabBarControllerPages(Array(pageAccepted, pageMaybe, pageDeclined), 0)
    End If
   
End Sub

Sub clv_Accepted_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub

Sub clv_Declined_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub

Sub clv_Maybe_ItemClick (Index As Int, Value As Object)
'This does not get called
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Why are you adding the layouts with AddView? It is a mistake. You should load the layout with pageAccepted.RootPanel.LoadLayout.

2. You don't need to create 3 different layouts. You need to use the tag property to distinguish between the CLVs:
B4X:
pnlAccepted.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "accepted"
pnlMaybe.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "maybe"
pnlDeclined.LoadLayout("loFeedDetail")
clv.GetBase.Tag = "declined"

B4X:
Sub clv_ItemClick (Index As Int, Value As Object)
 Dim clv1 As CustomListView = Sender
 Log(clv1.GetBase.Tag)
End Sub
 
Upvote 0

Rory Mapstone

Member
Licensed User
Longtime User
Ok thank you very much, I will also rectify the mistake. I had it that way because I was using the old custom list view library, which was not supported with the designer.
 
Last edited:
Upvote 0
Top