Android Question [Solved]StdViewPager and Statemanager?

Discussion in 'Android Questions' started by anOparator, Apr 26, 2016.

  1. anOparator

    anOparator Active Member Licensed User

    The StateManager.zip sample restores an Edittext which is on a Panel when the screen is rotated, but when I use StateManager.bas with StdViewPager I'm not finding how to restore the Edittext in my project.
    I've tried passing StateManager the Panel instead of the activity as the first parameter. (as listed below)
    Code:
    Sub Activity_Create(FirstTime As Boolean)
    ...
    StateManager.RestoreState(
    Activity"Main)"60)
    StateManager.RestoreState(
    Activity"Panels(svpTest.CurrentPage)"60)
    StateManager.RestoreState(
    Activity"svpTest.Panels(svpTest.CurrentPage)"60)
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
         StateManager.SaveState(
    Activity"Main")
         StateManager.SaveState(
    Activity"Panels(svpTest.CurrentPage")
         StateManager.SaveState(
    Activity"svpTest.Panels(svpTest.CurrentPage")
    End Sub
    Is there a way to get around the initialization after a screen rotation which resets 'CurrentPage' to zero, or what other way is there to get this to work?
    Thanks in advance
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Change your code to:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       pnlTest.Initialize(
    "")  ' screen rotation sets the current page to zero
       svpTest.Initialize("svpTest"4100%x100%y)
       
    Activity.AddView(svpTest.AsView, 00100%x100%y)
       
    Log("Create CurrentPage =  " & svpTest.CurrentPage)
       svpTest.Panels(
    3).AddView(pnlTest, 0,0100%x100%y)   
       svpTest.Panels(
    0).LoadLayout("0")
       svpTest.Panels(
    1).LoadLayout("1")
       svpTest.Panels(
    2).LoadLayout("2")
       svpTest.Panels(
    3).LoadLayout("3")
       
    For i = 0 To svpTest.Panels.Length - 1
         StateManager.RestoreState(svpTest.Panels(i), i, 
    60)
       
    Next
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
       
    For i = 0 To svpTest.Panels.Length - 1
         StateManager.SaveState(svpTest.Panels(i), i)
       
    Next
    End Sub
     
  3. anOparator

    anOparator Active Member Licensed User

    Thanks, I see the 'svpTest.Panels(3).AddView(pnlTest, 0,0, 100%x, 100%y)' thingy and have added the For loops but it still goes to page 0 when
    the screen rotates. I even tested with 'StateManager.SaveSettings' after Next in Sub Activity_Pause.
    What code could be missing?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The code I posted saves the panels state. It doesn't save the current selected page. It is very simple to add it:

    Code:
    Sub Activity_Pause (UserClosed As Boolean)
     StateManager.SetSetting(
    "CurrentPage", svpTest.CurrentPage)
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
     ...
     svpTest.ScrollTo(StateManager.GetSetting2(
    "CurrentPage"0), False)
    End Sub
     
    anOparator likes this.
  5. anOparator

    anOparator Active Member Licensed User

    Yes, basically beautiful powerful and simple. Thanks.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice