Android Question Need help getting nested CLV to work inside expanding CLV

tsteward

Well-Known Member
Licensed User
Longtime User
Hoping someone can look at the attached code and suggest how I can get expanding and nested CLV working together.
At the moment I can get both CLV's to display but the inner view will not scroll. Note I have commented out line 42.
 

Attachments

  • Lara2.zip
    18 KB · Views: 125

wes58

Active Member
Licensed User
Longtime User
Hoping someone can look at the attached code and suggest how I can get expanding and nested CLV working together.
At the moment I can get both CLV's to display but the inner view will not scroll. Note I have commented out line 42.
Have a look at attached example (this is modified your example from another thread https://www.b4x.com/android/forum/t...v-with-another-clv-inside.120983/#post-756416).
It is not exactly the project you had, but it just shows you how you could scroll CLV inside an expanded CLV.
I didn't use CLVExpandable.bas, and CLVNested.bas classes! I just used xCustomListView v1.72.
Maybe it can be done better, but it is up to you to work it out.

I hope it helps you.
 

Attachments

  • Lara2.zip
    17.1 KB · Views: 150
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Consider implementing it different: open a B4XDialog + B4XListTemplate when the user clicks on the vehicle maker.

This will help you get started with combining CLVNested with CLVExpandable:
B4X:
Private Sub GetInnerCLVFromTouch (x As Float, Y As Float) As CustomListView
    Dim index As Int = CLV.FindIndexFromOffset(Y + CLV.sv.ScrollViewOffsetY)
    Dim item As CLVItem = CLV.GetRawListItem(index)
    Dim ep As ExpandableItemData = item.Value '<---- new code in CLVNested
    If ep.Expanded = False Then
        Return Null
    End If
    If item.Panel.GetView(0).Tag Is CustomListView Then
        Dim inner As CustomListView = item.Panel.GetView(0).Tag
            
        If inner.AsView.Left <= x And inner.AsView.Left + inner.AsView.Width >= x Then Return inner
    End If
    Return Null
End Sub

Don't forget to set the tag in CreateItem:
B4X:
p.Tag = clvModels

You will probably need to make more changes.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Consider implementing it different: open a B4XDialog + B4XListTemplate when the user clicks on the vehicle maker.
I'd love to see and example of how you would do that! If you could spare me 5 minutes it would be appreciated.

I didn't know about B4XListTemplate and am having trouble finding examples that I understand.
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Just an update to the example I posted in the post #2:
In the sub CreateListItem(...) I had the code:
B4X:
Sub CreateListItem(c As carSearch, Width As Int, Height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("vehicleLV")
    schLblModel.Text = c.CModel
    schLblKeyway.Text = c.CKey
    schLblChip.Text = c.CChip
    
    Dim r As Reflector
    For Each v As B4XView In p.GetAllViewsRecursive
        r.Target = v
        r.SetOnTouchListener("lvModels_Touch")
    Next   
    Return p
End Sub
In this code I set the SetOnTouchListener on each view in the second CLV.

But I have realized, that it is enough, to set the SetOnTouchListener only on the new Panel p (B4XView).
So the code can be like this:
B4X:
Sub CreateListItem(c As carSearch, Width As Int, Height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("vehicleLV")
    schLblModel.Text = c.CModel
    schLblKeyway.Text = c.CKey
    schLblChip.Text = c.CChip
    
    Dim r As Reflector
    r.Target = p    'v
    r.SetOnTouchListener("lvModels_Touch")
    Return p
End Sub
So for the scrolling of the inside CLV we need to set SetOnTouchListener, and when this CLV is touched, we have to disable scrolling of the first CLV with the sub:
B4X:
Sub lvModels_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, EventData As Object) As Boolean
    Log("action " & Action)
    If Action = 0 Then                                    'ACTION_DOWN
        Dim r As Reflector
        r.Target = clvVehicles.sv
        r.RunMethod2("requestDisallowInterceptTouchEvent", True, "java.lang.boolean")
    End If   
    Return False
End Sub
I think, it makes the code simpler than using CLVnested class.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Thank you very much. Obviously got you thinking lol
 
Upvote 0
Top