B4J Question Issue with CLVExpandable not "Pushing" list up in B4J

MrKim

Well-Known Member
Licensed User
Longtime User
Erel quickly and graciously provided me with code to greatly improve (I think) CLVExpandable Here, IT works perfectly in B4A and B4i, however it doesn't work properly in B4J.

It works on the list items at the top of the list, but as you work your way down the list the "Push" gets smaller and smaller

This is the code Erel provided and a sample project is below. to replace the existing code in CLVExpandable.
B4X:
Public Sub ExpandItem (index As Int)
    ResizeItem(index, False)
    Dim item As CLVItem = mCLV.GetRawListItem(index)
    Dim delta As Int = item.Offset + item.Size - mCLV.sv.ScrollViewOffsetY - mCLV.AsView.Height
    If delta > 0 Then
        Sleep(5)
        Dim offset As Int = mCLV.sv.ScrollViewOffsetY + delta
        #if B4i
        Dim nsv As ScrollView = mCLV.sv
        nsv.ScrollTo(0, offset, True)
        #else if B4J
        mCLV.sv.ScrollViewOffsetY = offset
        #Else If B4A
        Dim nsv As ScrollView = mCLV.sv
        nsv.ScrollPosition = offset
    #End If
    End If
End Sub

The problem seems to be that delta gets smaller and smaller as yo go down through the list until, on the last couple of items it is actually negative.
Thanks for any help.
 

Attachments

  • CLVExpandableissue.zip
    5.5 KB · Views: 124

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not perfect as in B4A and B4i but it overall it works:
B4X:
Public Sub ExpandItem (index As Int)
    Dim item As CLVItem = mCLV.GetRawListItem(index)
    Dim currentOffset As Int = mCLV.sv.ScrollViewOffsetY
    Dim id As ExpandableItemData = item.Value
    Dim itemBottom As Int = item.Offset + id.ExpandedHeight
    ResizeItem(index, False)
    Dim delta As Int = itemBottom - currentOffset - mCLV.AsView.Height
    If delta > 0 Then
        Sleep(5)
        Dim offset As Int = itemBottom - mCLV.AsView.Height
        #if B4i
        Dim nsv As ScrollView = mCLV.sv
        nsv.ScrollTo(0, offset, True)
        #else if B4J
        Sleep(50)
        mCLV.sv.ScrollViewOffsetY = offset
        #Else If B4A
            Dim nsv As ScrollView = mCLV.sv
            nsv.ScrollPosition = offset
        #End If
    End If
End Sub
 
Upvote 0
Top