Here is the second example.
The difference from the post #1 are:
- clv2 is located in the cellitem.bal
- you can have more than one clv1 item expanded at the time
- all clv2 items are created when the clv1 is created. The advantage is that clv2 items retain value (like on/off, air con. fan lo/hi) after the clv1 item is collapsed and then expanded again.
All this created some problems with access to clv2 for a clicked item, so that's what has to be done:
- when creating clv1 item, clv1 value has to be set to clv2
For i = 0 To house.Size-1
clv1.Add(CreateListItem(house.Get(i), i),[B] [/B]clv2) 'clv1 value is set to created clv2
Next
- when creating clv2 items, clv2 value has to be set to clv1 item index
Select index
Case 0
For i = 0 To room1.Size-1
clv2.Add(CreateRoomItem(room1.Get(i), index), index) 'index of clv1 is needed as a value in clv2
Next
- if there are some clickable items on the clv2 - like in the example imageviews on the Air Con. item - you need to set the panel tag on which those items are to the clv1 item index.
Sub CreateRoomItem(text As String, index As Int) As B4XView 'for clv2
Dim clr, shade As Int
Dim status As Int = houseStatus.Get(index)
Dim p As B4XView = xui.CreatePanel("")
clr = Colors.RGB(233,221,175)
shade = ShadeColor(clr)
p.SetLayoutAnimated(0, 0, 0, clv1.AsView.Width, ExpandedHeight1)
If text.Contains("Air") Then
p.LoadLayout("catAC")
Else
p.LoadLayout("catAll")
End If
p.GetView(0).Tag = index
All this is required to get the clv2 for the clicked item.
For example if the button is clicked on clv1 we have:
Sub btnEvent1_Click ' event from any other "clickable" items on clv1
Dim j As Int
Dim btn As Button 'Label
Dim index As Int = clv1.GetItemFromView(Sender)
clv2 = clv1.GetValue(index) 'get clv2 from clv1 value
When we click on the imageviews in clv2 we have:
Sub clv2Event_Click 'clv2 items click
Dim i As Int
Dim v As B4XView
v = Sender
Dim parentIndex As Int = v.Parent.Tag 'panel on which imageView is located. tag is set to the clv1 item index
clv2 = clv1.GetValue(parentIndex)
Dim index As Int = clv2.GetItemFromView(Sender)
I know it looks complicated, but it wasn't easy to figure it out how to get it working.