Android Question Expand row in CLVExpandable

Sergey_New

Well-Known Member
Licensed User
Longtime User
I go through the index, for example, to the last row:
B4X:
CLV1.ScrollToItem(CLV1.Size-1)
How to programmatically expand a row by its index in CLVExpandable?
 
Solution
?
B4X:
    CLV1.ScrollToItem(CLV1.Size-1)
   
    Dim e As ExpandableItemData = CLV1.GetValue(CLV1.Size-1)
    If e.Expanded = False Then 'check if item is expanded
        CLVExpandable1.ToggleItem(CLV1.Size-1)
    End If

TILogistic

Expert
Licensed User
Longtime User
?
B4X:
    CLV1.ScrollToItem(CLV1.Size-1)
   
    Dim e As ExpandableItemData = CLV1.GetValue(CLV1.Size-1)
    If e.Expanded = False Then 'check if item is expanded
        CLVExpandable1.ToggleItem(CLV1.Size-1)
    End If
 
Last edited:
Upvote 1
Solution

TILogistic

Expert
Licensed User
Longtime User
or use new B4x
B4X:
    CLV1.ScrollToItem(CLV1.Size-1)
    
    If Not(CLV1.GetValue(CLV1.Size-1).As(ExpandableItemData).Expanded) Then 'check if item is expanded
        CLVExpandable1.ToggleItem(CLV1.Size-1)
    End If
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
It was required to add a Sleep(5) for a long list. Sleep(0) is small.
B4X:
Sub ExpandToItem(index As Int)
    If CLV1.Size = 0 Then Return
    CLV1.ScrollToItem(index)
    Sleep(5)
    Dim e As ExpandableItemData = CLV1.GetValue(index)
    If e.Expanded = False Then
        CLVExpandable1.ToggleItem(index)
    End If
End Sub
Thanks!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
?
ExpandToItem(CLV1.Size -1)
ExpandToItem(0)
B4X:
Sub ExpandToItem(index As Int) 
    If index < 0 Then Return 'items is 0 to n
    CLV1.ScrollToItem(index)
    Sleep(CLV1.AnimationDuration) 'test sleep
    Dim e As ExpandableItemData = CLV1.GetValue(index)
    If e.Expanded = False Then
        CLVExpandable1.ToggleItem(index)
    End If
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see Class CLVExpandable (mCLV.AnimationDuration)

you
CLV1.AnimationDuration=0

expander and customlistview will not have animation:
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I do not need animation, so for cases when it is needed, it seems to me that it will be correct:
B4X:
Sleep(CLV1.AnimationDuration+5)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This is your code:
B4X:
Sub ExpandToItem(index As Int)
    If CLV1.Size = 0 Then Return
    CLV1.ScrollToItem(index)
    Sleep(5)
    Dim e As ExpandableItemData = CLV1.GetValue(index)
    If e.Expanded = False Then
        CLVExpandable1.ToggleItem(index)
    End If
End Sub
Why not simply have the below code and get the same result:
B4X:
Sub ExpandToItem(index As Int)
    CLVExpandable1.ExpandItem(index)  'works to expand the given item
    Sleep(5)  
    clv1.ScrollToItem(index )
End Sub
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Why not simply have the below code and get the same result:
An error occurs.
It's probably right like this?:
B4X:
Sub ExpandToItem(index As Int)
    clv1.ScrollToItem(index )
    Sleep(5)
    CLVExpandable1.ExpandItem(index)  'works to expand the given item
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Have you tried to use the value to expand by instead of index. The index is abstract. You don;t usually know what is strored there. . Here it is. It works for me in B4A and B4J. You can adjust you sleep time and shuffle lines of code if it suits:
B4X:
ExpandToItem("mosc")
B4X:
Sub ExpandToItem(val As String)
    For i = 0 To clv1.Size -1
        Dim e As ExpandableItemData = clv1.GetValue(i)
        Dim s As String =e.Value
        If s.tolowercase.Contains(val.tolowercase) Then
            Sleep(0)
            clv1.ScrollToItem(i)
            Expandable.ExpandItem(i)
            Return
        End If
    Next
End Sub
 
Upvote 0
Top