Hi,
I'm trying to make a simple app with 3 pages.
Page1 with a button to call Page2 that hold a scroll view with 100 items. Click on each item will open Page3 that shows the selected item.
If I put code to load 100 items in Page2_appear event, the scroll view will be reload everytime I back from Page 3. Imagine if there's 300 items and the user scrolled to the end to select item 299, later he want to select item 298, he need to scroll again to the end of scrollview. It's waste of time and really annoying.
I write the code as below, I think its logical is right:
Page 1:
Page 2 (ScrollViewModule):
Page 3 (ResultModule):
Question 1: Why the scrollview never load when Page2 run first time? If I back to Page1 and call Page2 again, the scrollview will show up.
Question 2: Is there better way to avoid loading the scrollview again?
Please find attachment for the code.
Thank you guys.
I'm trying to make a simple app with 3 pages.
Page1 with a button to call Page2 that hold a scroll view with 100 items. Click on each item will open Page3 that shows the selected item.
If I put code to load 100 items in Page2_appear event, the scroll view will be reload everytime I back from Page 3. Imagine if there's 300 items and the user scrolled to the end to select item 299, later he want to select item 298, he need to scroll again to the end of scrollview. It's waste of time and really annoying.
I write the code as below, I think its logical is right:
Page 1:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private bt As Button
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
bt.InitializeCustom("bt", Colors.Blue, Colors.Black)
bt.Text = " Click Me "
bt.CustomLabel.SetBorder(1, Colors.Black, 2)
bt.CustomLabel.Font = Font.CreateNew(30)
Page1.RootPanel.AddView(bt, 0, 100dip, 200dip, 80dip)
End Sub
Sub bt_Click
ScrollViewModule.RemoveSV
ScrollViewModule.Show
ScrollViewModule.CreateScrollView
End Sub
Page 2 (ScrollViewModule):
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private pg As Page
Private sv As ScrollView
Private btname As Button
Public SelectedItem As Int
End Sub
Public Sub Show
If pg.IsInitialized = False Then
pg.Initialize("pg")
pg.Title = "Scroll View"
pg.RootPanel.Color = Colors.White
End If
Main.NavControl.ShowPage(pg)
End Sub
Public Sub CreateScrollView
sv.Initialize("sv", pg.RootPanel.Width, 0)
pg.RootPanel.AddView(sv, 0, 10dip, pg.RootPanel.Width, pg.RootPanel.Height-60dip)
For i=0 To 100
btname.InitializeCustom("btname", Colors.RGB(163,102,40), Colors.Black)
btname.CustomLabel.SetBorder(1, Colors.Black, 2)
btname.CustomLabel.Font = Font.CreateNew(25)
btname.Text = "Item #" & i
btname.Tag = i
sv.Panel.AddView(btname, sv.width/2 - 100dip/2, i*80dip, 150dip, 80dip)
Next
sv.ContentWidth = pg.RootPanel.Width
sv.ContentHeight = i * 80dip
End Sub
Private Sub btname_Click
Dim lbt As Button
lbt = Sender
SelectedItem = lbt.Tag
ResultModule.RemoveButton
ResultModule.Show
End Sub
Public Sub RemoveSV
If sv.IsInitialized Then
sv.RemoveViewFromParent
End If
End Sub
Page 3 (ResultModule):
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private pg As Page
Private bt As Button
End Sub
Public Sub Show
If pg.IsInitialized = False Then
pg.Initialize("pg")
pg.Title = "Result"
pg.RootPanel.Color = Colors.White
End If
Main.NavControl.ShowPage(pg)
bt.InitializeCustom("bt", Colors.Blue, Colors.Black)
bt.Text = "You Selected Item #" & ScrollViewModule.SelectedItem
bt.CustomLabel.Font = Font.CreateNew(24)
pg.RootPanel.AddView(bt, 50dip, 100dip, 250dip, 80dip)
End Sub
Public Sub RemoveButton
If bt.IsInitialized Then
bt.RemoveViewFromParent
End If
End Sub
Question 1: Why the scrollview never load when Page2 run first time? If I back to Page1 and call Page2 again, the scrollview will show up.
Question 2: Is there better way to avoid loading the scrollview again?
Please find attachment for the code.
Thank you guys.