Android Question Horizontal & Vertical Scrolling : CustomListView & StdViewPager

Mashiane

Expert
Licensed User
Longtime User
Hi there

I am using a CustomListview for horizontal scrolling. Each list item is assigned a tag property from a map.

Inside each list item, I have 6 pages defined using a StdViewPager. So far I am able to do this. The thing is, I need to get the tag property of the parent list item panel.

It would be easy if the StdViewPager had a tag property as I would just assign the list item tag to that but it does not, so I want to get the tag property of the parent panel instead.

B4X:
Sub CreateUpDownPage(fMap As Map) As Panel
    Dim pager As StdViewPager
    Dim p As Panel
    user_to_name = fMap.Get("user_to_name")
    user_to = fMap.Get("user_to")
    p.Initialize("")
    p.LoadLayout("votherdays")
    p.Color = Colors.White
    imgOtherUser.tag = "user" & user_to
    lblOtherUser.Text = user_to_name
    ' add a pager to the listitem with 6 pages
    pager.Initialize("Pager", 6, 100%x, 100%y)
    p.AddView(pager.asview, 0dip, 70dip, 100%x, 510dip)
    p.Tag = fMap
    Return p
End Sub

This code above works well for each list item. Now I'm stuck below

B4X:
Sub Pager_PageSelected (Position As Int)
    ' when a page changes, read the tag of the parent panel
    ' and display respective content
    CurrentPage = Position
    Dim pg As StdViewPager
    Dim pnl As Panel
    pg = Sender
    ' get parent panel ??
End Sub

Log(pg) here including the current page works fine. How do I get the parent panel and then gets its tag property? Can someone please advise? Thanks a lot!
 

Mashiane

Expert
Licensed User
Longtime User
After careful thought, figured it out a usable solution...

B4X:
Sub CreateUpDownPage(fMap As Map) As Panel
    Dim pager As StdViewPager
    Dim p As Panel
    user_to_name = fMap.Get("user_to_name")
    user_to = fMap.Get("user_to")
    p.Initialize("")
    p.LoadLayout("votherdays")
    p.Color = Colors.White
    imgOtherUser.tag = "user" & user_to
    lblOtherUser.Text = user_to_name
    ' add a pager to the listitem with 6 pages
    pager.Initialize("Pager", 6, 100%x, 100%y)
    p.AddView(pager.asview, 0dip, 70dip, 100%x, 510dip)
    pager.Panels(0).Tag = fMap 
    pager.Panels(1).Tag = fMap
    pager.Panels(2).Tag = fMap
    pager.Panels(3).Tag = fMap
    pager.Panels(4).Tag = fMap
    pager.Panels(5).Tag = fMap
    p.Tag = fMap
    Return p
End Sub

and

B4X:
Sub Pager_PageSelected (Position As Int)
    ' when a page changes, read the tag of the parent panel
    ' and display respective content
    CurrentPage = Position
    ' fix the days
    ChangeHeaderOnPageMove
    Dim pg As StdViewPager
    Dim parent As Map
    pg = Sender
    parent = pg.Panels(CurrentPage).tag
    Log(parent)
    ' get parent panel ??
End Sub

This gives me the tag each time I slide the page. Perfect!!!
 
Upvote 0
Top