B4J Question [Accordion] This is almost driving me crazy, and I haven't even started coding it!!!!

Cableguy

Expert
Licensed User
Longtime User
Hi Gurus

I have an accordion, no issues there...
My issue is, each TitledPane will have a ListView, that will be loaded into the TitledPane using the LoadLayout method...
So, my issue is, each Listview will be named as ListView1...
(My head is already acking just from trying to figure out how to write this...)
So, these listviews will be populated by "template" layouts, so I may have 2 layouts of one template and 6 of another in them...
I cannot simply use the views names, so the best approach would be to create some sort of node-list for each titled pane in the accordion...(??)

How would you guys do this?

In a paper its a lot more simple than in code, because you just draw it in place, but in code, dynamically referencing different views that have the same name, for me, is very complicated concept to grasp!
 

Daestrum

Expert
Licensed User
Longtime User
This may help - it shows how to access the listview inside a titled pane even though they have the same names.
(just a simple example - needs extra code to handle clicking from one titled pane to another
- currently crashes if you don't close previous pane before selecting next one)

Layout 'lay1' is simply a 150x300 variant with a listview in it.

B4X:
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Dim acc As Accordion
 Private ListView1 As ListView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 MainForm.Show
 
 acc.Initialize("acc")
 acc.LoadLayout("lay1","one")
 For a = 0 To 5
  ListView1.Items.Add(a)
 Next
 acc.LoadLayout("lay1","two")
 For a = 0 To 5
  ListView1.Items.Add(a+10)
 Next
 MainForm.RootPane.AddNode(acc,0,0,100,200)
End Sub
Sub acc_PaneChanged (ExpandedPane As TitledPane)
 If acc.SelectedIndex <> -1 Then 
  Log("pane "&ExpandedPane.Text&" expanded")
  Dim lv As ListView = ExpandedPane.Content.GetNode(0) ' the listview
  Log("item #2 "& lv.Items.Get(2))
 End If
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
 Return True
End Sub
 
Upvote 0
Top