I have been using AHViewPager in one app for several years now without any problems, but when I try to update it to use the new version, I cannot get it to work. I've been having different problems with it. In this example, I load a layout with just the ViewPager on it, and then load two other layouts, one for each page. Problem seems to be that _PageCreated event doesn't fire when the Activity_Create runs and therefore doesn't load the layout files, so when Activity_Resume runs it sees the Edit Text boxes, as Uninitialized.
Looking for some explanation for this ... the old AHViewPager was working fine, but I want to stay up to date with Corwin's updates.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'Activity module Settings - Configuration
Sub Process_Globals
'These global variables will be declared once when the application starts.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private edtUserName As EditText
Private edtUserPassword As EditText
Private edtMySQLLink As EditText
Private pcSettings As PageContainer
Private vpSettings As ViewPager
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer.
' For example: Load the Configuration layout
Dim sErrorMsg As String, sCodeName As String 'ignore
sCodeName = "TMM_Preferences.A_C"
Log(sCodeName)
Activity.LoadLayout("settings_pager")
pcSettings.Initialize
' Add pages
For i = 0 To 1
pcSettings.AddPage(i)
Next
vpSettings.PageContainer = pcSettings
vpSettings.GotoPage(0, False)
End Sub
Sub Activity_Resume
Dim sErrorMsg As String, sCodeName As String 'ignore
sCodeName = "TMM_Preferences.A_R"
Log(sCodeName)
edtMySQLLink.SingleLine = True
edtUserName.SingleLine = True
edtUserPassword.SingleLine = True
edtUserPassword.PasswordMode = True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Dim sErrorMsg As String, sCodeName As String 'ignore
sCodeName = "TMM_Preferences.A_P"
Log(sCodeName)
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
'return true if you want to consume the event
'"True" will stop it from closing the activity.
Return False
End Sub
Sub vpSettings_PageCreated (Position As Int, Page As VPage)
If Not(Page.AlreadyCreated) Then
Log("New Page " & Position & " Created.")
If Position = 0 Then Page.Panel.LoadLayout("tmm_preferences_page1_std")
If Position = 1 Then Page.Panel.LoadLayout("tmm_preferences_page2_std")
Else
Log("Page " & Position & " already exists.")
End If
End Sub
Sub vpSettings_PageDestroyed (Position As Int, Page As VPage)
End Sub
Sub vpSettings_PageChanged (Position As Int)
Log("Settings Page Changed to " & Position)
End Sub
#End Region