I'm continuing this thread from B4A. Its a viewPager with Xclv inside.
I'm trying to convert my code to B4i and it works but i have two major problems:
1. can't figure how to set viewPager Size as it goes beyond screen size.
2. Scrolling list inside view pager is very slow.
Thanks for any help
I'm trying to convert my code to B4i and it works but i have two major problems:
1. can't figure how to set viewPager Size as it goes beyond screen size.
2. Scrolling list inside view pager is very slow.
B4XMainPage:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private ASViewPager1 As ASViewPager
Private CustomListView1 As CustomListView 'Step1
Dim xpnl As B4XView
Private Label1 As Label
Private lFles As List
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
lFles.Initialize
lFles.AddAll(Array As String("davidbowie.txt", "queen.txt", "thebeatles.txt"))
Log(lFles.Size)
For i = 0 To lFles.Size-1
xpnl = xui.CreatePanel("")
xpnl.SetLayoutAnimated(0, 0, 0, ASViewPager1.Base.Width, ASViewPager1.Base.Height)
ASViewPager1.AddPage(xpnl,"")
xpnl.LoadLayout("list")
CustomListView1.AsView.Tag = CustomListView1'Step2
Next
ASViewPager1_PageChanged(0)'Step3 - just to have a filled first page
End Sub
Private Sub B4XPage_Appear
' ASViewPager1_PageChanged(ASViewPager1.CurrentIndex)'Step3 - just to have a filled first page
End Sub
Sub ASViewPager1_PageChanged (index As Int)
Log("PageChanged: " & index)
Dim CustomListView1 As CustomListView = ASViewPager1.CustomListView.GetPanel(index).GetView(0).Tag 'Step4
CustomListView1.clear
Dim lineCounter As Int = 0
Dim iWdth As Int = CustomListView1.AsView.Width
Dim iHght As Int = 55dip
B4XPages.SetTitle(Me, lFles.Get(index))
#if B4A
'Each list item of files produce a new list with the file items in a new ViewPager
Private Reader As TextReader
Reader.Initialize(File.OpenInput(File.DirAssets, lFles.Get(index)))
Private line As String
line = Reader.ReadLine
Do While line <> Null
Log(line)
CustomListView1.InsertAt(lineCounter, CreateListItem(line, iWdth, iHght), line)
line = Reader.ReadLine
lineCounter = lineCounter + 1
Loop
Reader.Close
#else if b4i
Dim s As String = File.ReadString(File.DirAssets, lFles.Get(index))
Dim l1 As List = Regex.Split("[\r\n]+", s)
For i = 0 To l1.Size-1
CustomListView1.InsertAt(lineCounter, CreateListItem(l1.Get(i), iWdth, iHght), l1.Get(i))
lineCounter = lineCounter + 1
Next
#end if
End Sub
Private Sub CreateListItem(Text As String, Width As Int, Height As Int) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 10dip, 10dip, Width, Height)
p.LoadLayout("CellItem")
Label1.Text = Text
'Note that we call DDD.CollectViewsData in CellItem designer script. This is required if we want to get views with dd.GetViewByName.
' dd.GetViewByName(p, "Label1").Text = Text
' CustomListView1.Add(p, "")
Return p
End Sub
Private Sub ASViewPager1_SwipeOnEndOfPage
Log("SwipeOnEndOfPage")
End Sub
Private Sub xlbl_next_Click
ASViewPager1.NextPage
End Sub
Thanks for any help
Attachments
Last edited: