State Save WebView

jeanbiazon

New Member
Licensed User
Longtime User
Please, is possible save state with WebView in the StateManager file ? :BangHead:

I´m add in the file this code, but do not work....


Sub innerSaveState(v As View, list1 As List)
Dim data() As Object
If v Is EditText Then
Dim edit As EditText
edit = v
data = Array As Object(edit.Text, edit.SelectionStart)
Else If v Is Spinner Then
Dim spinner1 As Spinner
spinner1 = v
data = Array As Object(spinner1.SelectedIndex)
Else If v Is CheckBox Then
Dim check As CheckBox
check = v
data = Array As Object(check.Checked)
Else If v Is RadioButton Then
Dim radio As RadioButton
radio = v
data = Array As Object(radio.Checked)
Else If v Is ToggleButton Then
Dim toggle As ToggleButton
toggle = v
data = Array As Object(toggle.Checked)
Else If v Is SeekBar Then
Dim seek As SeekBar
seek = v
data = Array As Object(seek.Value)
Else If v Is TabHost Then
Dim th As TabHost
th = v
data = Array As Object(th.CurrentTab)
For i = 0 To th.TabCount - 1
th.CurrentTab = i
Next
list1.Add(data)
Dim data() As Object
Dim r As Reflector
r.Target = th
Dim tabParentPanel As Panel
tabParentPanel = r.RunMethod("getTabContentView")
For i = 0 To tabParentPanel.NumberOfViews - 1
innerSaveState(tabParentPanel.GetView(i), list1)
Next
Else If v Is ScrollView Then
Dim sv As ScrollView
sv = v
data = Array As Object(sv.ScrollPosition)
list1.Add(data)
Dim data() As Object
innerSaveState(sv.Panel, list1)
Else If v Is Panel Then
Dim panel1 As Panel
panel1 = v
For i = 0 To panel1.NumberOfViews - 1
innerSaveState(panel1.GetView(i), list1)
Next
Else If v Is WebView Then
Dim webview1 As WebView
webview1 = v
data = Array As Object(webview1.Url)
End If
If data.Length > 0 Then list1.Add(data)
End Sub



Sub innerRestoreState(v As View, list1 As List)
Dim data() As Object
If v Is EditText Then
Dim edit As EditText
edit = v
data = getNextItem(list1)
edit.Text = data(0)
edit.SelectionStart = data(1)
Else If v Is Spinner Then
Dim spinner1 As Spinner
spinner1 = v
data = getNextItem(list1)
spinner1.SelectedIndex = data(0)
Else If v Is CheckBox Then
Dim check As CheckBox
check = v
data = getNextItem(list1)
check.Checked = data(0)
Else If v Is RadioButton Then
Dim radio As RadioButton
radio = v
data = getNextItem(list1)
radio.Checked = data(0)
Else If v Is ToggleButton Then
Dim toggle As ToggleButton
toggle = v
data = getNextItem(list1)
toggle.Checked = data(0)
Else If v Is SeekBar Then
Dim seek As SeekBar
seek = v
data = getNextItem(list1)
seek.Value = data(0)
Else If v Is TabHost Then
Dim th As TabHost
th = v
data = getNextItem(list1)
For i = 0 To th.TabCount - 1
th.CurrentTab = i
Next
th.CurrentTab = data(0)
Dim r As Reflector
r.Target = th
Dim tabParentPanel As Panel
tabParentPanel = r.RunMethod("getTabContentView")
For i = 0 To tabParentPanel.NumberOfViews - 1
innerRestoreState(tabParentPanel.GetView(i), list1)
Next
Else If v Is ScrollView Then
Dim sv As ScrollView
sv = v
data = getNextItem(list1)
sv.ScrollPosition = data(0)
DoEvents
sv.ScrollPosition = data(0)
innerRestoreState(sv.Panel, list1)
Else If v Is Panel Then
Dim panel1 As Panel
panel1 = v
For i = 0 To panel1.NumberOfViews - 1
innerRestoreState(panel1.GetView(i), list1)
Next
Else If v Is WebView Then
Dim webview1 As WebView
data = getNextItem(list1)
webview1 = v
innerRestoreState(webview1.LoadUrl(data(0)), list1)
End If
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

This code is wrong:
B4X:
Else If v Is WebView Then
Dim webview1 As WebView
data = getNextItem(list1)
webview1 = v
innerRestoreState(webview1.LoadUrl(data(0)), list1)
End If
End Sub

It should be:
B4X:
Else If v Is WebView Then
Dim webview1 As WebView
data = getNextItem(list1)
webview1 = v
webview1.LoadUrl(data(0))
End If
End Sub
 
Upvote 0
Top