AHViewPager problem with web pages

Smee

Well-Known Member
Licensed User
Longtime User
I have the following code snippet


B4X:
Sub Globals

   Dim WebViews(8) As WebView   
   Dim panels(8) As Panel

End Sub

Sub Activity_Create(FirstTime As Boolean)

   'Initialize the pages and add them to the layout object
   layout.Initialize
   For i = 0 To panels.Length - 1
         panels(i).Initialize("")
         panels(i).LoadLayout("WebViewTest.bal")
         WebViews(i).Initialize("WebView1")
         WebViews(i).LoadURL("file:///android_asset/baby671.htm")   
         WebViews(i).SetLayout(0, 0, 800, 1000)
         'WebView1.LoadURL("file:///android_asset/baby671.htm")   
      layout.AddPage(panels(i),"Page " & i)
   Next
   pager.Initialize(layout, "")
   
   Activity.AddView(pager, 0, 40dip, Activity.Width, Activity.Height-48dip-40dip)

End Sub

if I take out WebViews(i).SetLayout(0, 0, 800, 1000)
then the program will run but it does not show any of the web pages.

Can anyone advise why this is not working?

TIA
 

DarkMann

Member
Licensed User
Longtime User
Hi,

There doesn't appear to be any link between the Webview and the array. When you load the page layout onto the panel, there is no link to the WebViews() array. You need something like:-

B4X:
WebViews(i)=LoadedWebViewLayout

or whatever it is called in your WebViewTest.bal file.

I'm still not sure it will all work though. If you are going to have to resize the WebView anyway, why not just add each member of the array to the appropriate panel and get rid of the layout file?

B4X:
Sub Activity_Create(FirstTime As Boolean)

    'Initialize the pages and add them to the layout object
    layout.Initialize
    For i = 0 To panels.Length - 1
            panels(i).Initialize("")
 '           panels(i).LoadLayout("WebViewTest.bal")
            WebViews(i).Initialize("WebView1")
            panels(i).AddView(WebViews(i),0,0,800,1000)
            WebViews(i).LoadURL("file:///android_asset/baby671.htm")    
'            WebViews(i).SetLayout(0, 0, 800, 1000)
            'WebView1.LoadURL("file:///android_asset/baby671.htm")    
        layout.AddPage(panels(i),"Page " & i)
    Next
    pager.Initialize(layout, "")
    
    Activity.AddView(pager, 0, 40dip, Activity.Width, Activity.Height-48dip-40dip)

End Sub

(Not Tested)

David
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
tHANKS FOR the reply David

Nah that does not work either

:BangHead:

Trouble is the more attempts at getting it working when not fully understanding the whole process tends to make the code worse
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
OK this works but the htm file is not shown on any of the pages

B4X:
   For i = 0 To panels.Length - 1
         panels(i).Initialize("")
         panels(i).LoadLayout("WebViewTest.bal")
         WebViews(i).Initialize("WebView1")
         WebViews(i).LoadUrl("file:///android_asset/baby671.htm")   
'         WebView1.LoadURL("file:///android_asset/baby671.htm")   
'         WebViews(i).SetLayout(0, 0, 800, 1000)
'         WebView1.SetLayout(0, 0, 800, 1000)
         'WebView1.LoadURL("file:///android_asset/baby671.htm")   
'         panels(i).AddView(WebView2, 0, 0,Activity.Width,Activity.Height)
      layout.AddPage(panels(i),"Page " & i)
   Next

Any ideas why the htm file does not show?


SORTED:
B4X:
   For i = 0 To panels.Length - 1
         panels(i).Initialize("")
         WebViews(i).Initialize("WebView1")
         WebViews(i).LoadUrl("file:///android_asset/baby671.htm")   
         panels(i).AddView(WebViews(i), 0, 0,Activity.Width,Activity.Height)
      layout.AddPage(panels(i),"Page " & i)
   Next


nOW TO WORK ON using different pages in the PageChanged Event
 
Last edited:
Upvote 0

DarkMann

Member
Licensed User
Longtime User
Hi again,

Your snippet of code doesn't tell me enough about the setup of the AHViewPager setup. I have only used it for testing, not in anger yet and am not familiar enough with it to help with that part.

Your code still does not seem to be making any sort of link between what you are loading in the layout file and what you are doing with your array of Webviews.

The reason it works - you get no errors - is because it is loading the web page into the WebView, but the Webview doesn't exist on any panel because there is no reference to whatever your layout file contains and the Webview has not been added to the panel.

What is the name of the webview in your layout file?

David

EDIT:

Glad you got it sorted!
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
You are correct with the layout file David.

It was a left-over from earlier test code. I should have removed it. As you can see from the final snippet reference to it has gone.

Thanks for the pointer

One of the things i have to work out now is how to reduce the webviews(8) down to 3 or 5 and have them in a loop so that when the user gets to the last panel the next panel would be the first one and when going backwards the next panel after the first would be the last.

I have been trying various things but i have not got anything working yet that is a smooth transition

Any ideas here?

Cheers

Joe
 
Upvote 0

DarkMann

Member
Licensed User
Longtime User
Hi Joe,

I have had a look at the idea of continuous paging and am now intrigued.

I can get it to work, but as you say, it isn't smooth, as at the moment it jumps around a bit.

I have some ideas, but need more time to have a look at it. It does look like it makes a nice interface, although I notice that most apps don't roll round to the beginning.

Sadly, I don't have a use for it at the moment, but may work on it never the less.

David
 
Upvote 0
Top