Android Question clv into viewpager

pliroforikos

Active Member
Licensed User
Hello,
i'm trying to use one clv to show names of students from various classes.
I want to use a viewpager to swap to classes.

I tried this taken from viewpager example but i cant see the lists but only in the last page.
Any idea please?

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ASViewPager1 As ASViewPager
    Private CustomListView1 As CustomListView
    Dim xpnl As B4XView
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frm_main")
    #If B4I
    Sleep(250)
    #End If

    For i = 0 To 3
        xpnl = xui.CreatePanel("")
        xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
        xpnl.LoadLayout("list")
        ASViewPager1.AddPage(xpnl,i +1)
'        Label1.Text = "View " & i
    Next
    B4XPages.SetTitle(Me,"ASViewPager Example | Page " & 1 & "/" & ASViewPager1.Size)
End Sub


Sub ASViewPager1_PageChanged (index As Int)
    Log("PageChanged: " & index)
    B4XPages.SetTitle(Me,"ASViewPager Example | Page " & (index +1) & "/" & ASViewPager1.Size)
    CustomListView1.clear

    If index = 0 Then
        For i = 1 To 20
            CustomListView1.AddTextItem($"Item #${i}"$, $"Item #${i}"$)
        Next
    else if index = 1 Then
        For i = 21 To 40
            CustomListView1.AddTextItem($"Item #${i}"$, $"Item #${i}"$)
        Next
    else if index = 2 Then
        For i = 41 To 60
            CustomListView1.AddTextItem($"Item #${i}"$, $"Item #${i}"$)
        Next
    else if index = 3 Then
        For i = 61 To 80
            CustomListView1.AddTextItem($"Item #${i}"$, $"Item #${i}"$)
        Next
    End If
End Sub


Private Sub ASViewPager1_SwipeOnEndOfPage
    Log("SwipeOnEndOfPage")
End Sub


Private Sub xlbl_next_Click
    ASViewPager1.NextPage
End Sub

1666726257728.png
1666726288700.png
1666726309435.png
1666726239002.png
 

Attachments

  • Project.zip
    18.6 KB · Views: 91

Alexander Stolte

Expert
Licensed User
Longtime User
Any idea please?
You really don't know why? I'll try to explain why it doesn't work.

1666728061343.png

And how should the CustomListView1 above know which of the 4 pages you want to access? In the object above only the last added xclv is in there, therefore you see also only on the last side a full listview.

Look in the attachment and search for "step" i made you a step1 - step4 tutorial what you need to do, to get this right.
 

Attachments

  • B4X Example.zip
    13.8 KB · Views: 95
Upvote 0

pliroforikos

Active Member
Licensed User
Thank you.

Could you please explain what these two commands do?

B4X:
CustomListView1.AsView.Tag = CustomListView1'Step2

Dim CustomListView1 As CustomListView = ASViewPager1.CustomListView.GetPanel(index).GetView(0).Tag 'Step4
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Could you please explain what these two commands do?
Since the CustomListView does not reference itself in the tag object for historical reasons, we need to do this so that we can then address the correct customlistview later.

Dim CustomListView1 As CustomListView = ASViewPager1.CustomListView.GetPanel(index).GetView(0).Tag 'Step4
We fetch from the ASViewpager, from the page where we are, the panel where the customlistview is on it. And so that we can address the customlistview, we have to look in the tag object, because we have put it there in the 1st step.

I am bad at explaining
 
Upvote 0

pliroforikos

Active Member
Licensed User
I made a few changes for someone newbie like me wants to use it.

The example use 3 files to load some song list into ASViewpager. Each singer in different page.

Thank you Alexander.

1667726460192.png
1667726500158.png
1667726557181.png


Data was taken from Wikipedia
 

Attachments

  • Project.zip
    21.5 KB · Views: 90
Upvote 0
Top