Android Question CLVExpandable - collapse existing and open selected

mfstuart

Active Member
Licensed User
Longtime User
Hi all,
Based on Erel's library: https://www.b4x.com/android/forum/t...g-or-collapsing-xcustomlistview-items.106148/
How would the code be changed to: when selecting another item, the currently expanded item would close?
Take a look at Androids Contacts app to see what I mean.

I have tried this in the Main activity:
B4X:
Sub Globals
    Private clv1 As CustomListView
    Private lblTitle As B4XView
    Private pnlTitle As B4XView
    Private pnlExpanded As B4XView
    Private xui As XUI
    Private expandable As CLVExpandable
    Private prevIndex As Int        '<== added this
End Sub

Now in the clv1_ItemClick event handler:
B4X:
Sub clv1_ItemClick(Index As Int, Value As Object)
    If prevIndex >= 0 Then
        expandable.CollapseItem(prevIndex)
    End If
    expandable.ExpandItem(Index)
    prevIndex = Index
End Sub

Problem: touching an item for the first time, expands it. Touching the same item again, collapses it, but touching the same item again, does not expand it.
I've searched the forum for a solution, but nothing.

Anyone know how this should work?

Thanx,
Mark Stuart
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tracking state is difficult. Go with the simpler option:
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    For i = 0 To clv1.Size - 1
        If i = Index Then Continue
        Dim e As ExpandableItemData = clv1.GetValue(i)
        If e.Expanded Then 
            expandable.CollapseItem(i)
            Sleep(clv1.AnimationDuration)
        End If
    Next
    expandable.ToggleItem(Index)
End Sub
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Erel, thank you.

The expand and collapse are so smooth with this new code.
I get excited to see this work so well.

I continue to confirm myself and my colleagues that, THIS IS THE TOOL FOR MOBILE DEVELOPMENT, WITHOUT A DOUBT!!

Thanx again,
Mark Stuart
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Thanx for the tip. In the CLVExpandable class, I set the AnimationDuration to this:
B4X:
Public Sub Initialize (CLV As CustomListView)
    mCLV = CLV
    mCLV.AnimationDuration = 140       '<== changed it to this, seems to be an OK speed.
End Sub
 
Upvote 0
Top