Android Question How to handle ViewPager and xCustomListView?

FrankBerra

Active Member
Licensed User
Longtime User
Hello everyone
I am trying to handle ViewPager (https://www.b4x.com/android/forum/threads/viewpager-cleaned-up-viewpager.75342/) and xCustomListView (https://www.b4x.com/android/forum/t...-cross-platform-customlistview.84501/#content) in a simpler mode as possible but i fallen in trouble.

In my dream i want to have an undefined number of pages in ViewPager and every page should contain a xCustomListView (and every xCustomListView should containt it's items):
Page1 -> xCustomListView1 -> Item1, Item2, Item3
Page2 -> xCustomListView2 -> Item4, Item5
Page3 -> xCustomListView3 -> Item6, Item7, Item8
etc. etc.

I am able to use ViewPager and i am able to use and load items in xCustomListView.

Let's see the following example: since i don't know how many pages a ViewPager is going to hold i don't know how many layout with a xCustomListView i need.
B4X:
Sub ViewPager_PageCreated (Position As Int, Page As VPage)
    If Page.AlreadyCreated = True Then
        'Log("Page already created => do nothing")
    Else
        'Log("New Page => load the layout")
        'We load a simple layout file here.
        Page.Panel.LoadLayout("LayoutWithThexCustomListView")
    End If
End Sub


If i use the following approach i can add as many xCustomListView i want but i can't access to xCustomListView from other subroutines for adding items:
B4X:
Sub ViewPager_PageCreated (Position As Int, Page As VPage)
    If Page.AlreadyCreated = True Then
        'Log("Page already created => do nothing")
    Else
        'Log("New Page => load the layout")
        'We load a simple layout file here.

        Dim xScroll as CustomListView
        xScroll.Initialize ("", "something")
        Page.Panel.AddView(xScroll, 0, 0, 100%x, 100%y)
    End If
End Sub

So my question: is there a solution for this problem since i don't know how many pages a ViewPager is going to hold?

Thanks in advance
 

FrankBerra

Active Member
Licensed User
Longtime User
Is it possible to create just one layout containing the CLV and then use the same layout multiple times in all pages of ViewPager (but of course load different items in each CLV)? If yes, any example about how to recycle the same layout?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Sorry, but i feel confused how to do it. Here an example on what i understood:

B4X:
Sub Globals
   Dim xScroll as CustomListView
   Dim ScrollersContainer as List 
End sub

Sub Activity_Create(FirstTime As Boolean)
   ScrollersContainer.Initialize
   For i = 0 to 10
     dim Pan as Panel
     Pan.LoadLayout("LayoutContainingThexScroll") 'I load the layout again here and the global variable xScroll points to the last CLV
     ScrollersContainer.Add(xScroll) 'I add the last CLV to a list
   Next
End Sub

If i understood right, at the end of the For-Next, the global variable points to the last CLV but if i want to access to another CLV and add items to it i should do something like:

B4X:
Dim PreviousScroller as CustomListView
PreviousScroller = ScrollersContainer.Get(4)
PreviousScroller.add(...)

Is it right?
 
Upvote 0
Top