Can I add a back button above a webview and size problem

Malky

Active Member
Licensed User
Longtime User
Yes, I'm back.

I found a few nice things for webview, but as some new phones do not have the back button, I want a Back button at the top of the screen and beleow that a webview with a file from the sdcard.

I get the file and the button, but I cannot scroll the webview down, so therefor my anchor links dont work! It is only a help page.

Is it possible to get the webview to scroll full length using this method?

Malky
 
Last edited:

Malky

Active Member
Licensed User
Longtime User
No joy, I am getting a NULLPointer error with the ht variable when using the StrUtils function?
B4X:
Dim txt As String
         btnHelpBack.Text = DictionList(7)
         Dim lbldumm As Label
         Dim ht As Float
         lbldumm.Initialize("")
         
         'filename = File.DirAssets & "help.html"
         'wbvHelp.LoadURL(SD_PATH & "/help.html")
         txt = File.GetText(File.DirAssets,  "help.html")
         Log("Text = " & txt)
         lbldumm.Text = txt
         ht = StrUtils.MeasureMultilineTextHeight(lbldumm,txt)
         
         pnlHelp.Height = ht + 45dip
         wbvHelp.Height = pnlHelp.Height
         wbvHelp.LoadURL(SD_PATH & "/help.html")
         lbldumm.Visible = False
         scvMenu.Visible = False
         pnlHelp.Visible = True
         wbvHelp.Visible = True
The text is there as I have checked it, to the txt and the label.Text vars contain the whole html?
I use this already in the app but for a downloaded string. I can't see how the html should be treated any differently?

Any ideas? Incidentally does anyone know if the anchor tags work inside a 'local' URL this way?

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus, I wasn't aware that I had to attach the label as I don't even want to use it (except for sizing as you can see).

Perhaps I can add it, size it, but keep it invisible?

It is just a Panel containing a button at the vey top to return to the menu and a Webview underneath the button to display the html, that's all!

It was appearing, but the Webview and panel wouldn't resize to the size of the html file, which is why I tried this method.

Strange that you mention a scrollview, I was just having a break from work and thought about changing the panel to a scrollview!

Cheers,

Malky
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The MeasureMultilineTextHeight function needs to know the width, TypeFace and TextSize of the Label to caculate the height.
I speak of a ScrollView because that's what is used in the LongTextSimple example.
And in your code I saw this scvMenu.Visible = False supposing that you have a ScrollView.

The principle with the ScrollView is :
- the ScrollView size fits into the screen dimensions.
- the Label holding the text is added to the internal panel of the scrollview, it's heigher than the screen. The internal panel height must be at least as heigh as the label.
- the scrolling is managed by the ScrollView.

I have never tested a long text in a WebView.
I don't really understand how you want to implement this with a Panel and a WebView and how the scrolling is managed.

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus, thanks for that.

I'll replace the panel for a scrollview when I get home and set the label to suit the width etc then make it invisible.

The reason I am using a Webview is, it's just a Help information page with simple navigation.

At the top, there will be anchor links, such as Settings, Search and all other options in the app and you can tap them to move down (hopefully) to the proper part of the html file and tap a 'Back to top'. option as in a real web page.
That's the theory at least :) Just hoping internal anchor links work this way? It works in a normal browser.

I'll post my results anyway for the benefit of others.

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Ok, tried this and I see the scroll bar moving down but the text doesn't?

The scrollview size looks more than enough in height, but there is no movement in the html page?

Has anyone tried using a webview inside scrollview? Just to know if this actually works?
B4X:
btnHelpBack.Text = DictionList(10)
         Dim ht As Float
         Dim txt As String
          Dim lblText As Label
         lblText.Initialize("")
         scvHelp.Panel.AddView(lblText, 0dip, 0dip, 100%x, 50dip) 'Height 50
         txt = File.GetText(File.DirAssets, "help.html")
          lblText.Text = txt                    ' set the text string to the Label text property
            ht =     StrUtils.MeasureMultilineTextHeight(lblText, txt)
         Log("height = " & ht)

         
         scvHelp.Panel.Height = ht + 45dip
         Log("SCV height = " & ht)
         wbvHelp.Height = scvHelp.Height
         wbvHelp.LoadURL("file:///android_asset/" & "help.html")
         lblText.Visible = False
         scvMenu.Visible = False
         scvHelp.Visible = True
         wbvHelp.Visible = True

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi again Klaus, I've attached the zip.

I think I created everything the right way and the code I posted is the resizing part?

Would be fine if you spot anything stupid, as I don't want to look for an alternative method if possible?

Cheers,

Malky
 

Attachments

  • homer.zip
    88.9 KB · Views: 213
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your program.
It would be easier to help you if posted a small project that shows the problem.
The problem is that you have two ScrollViews visible at the same time !
I did'nt check which one I is still visible, I set all Visible properties to False.

Another problem, you calculate the height with the html text in the Label but in the WebView you have the result of the html text which are not the same.
To test if it works with a WebView I suggest you to make a small test project.

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Klaus thanks for looking.

As soon as I can, will investigate what you have said and if need be make up a small test prog to see if it works.

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi Kluas, just for the record, it appears that anchor links in the same html file DO NOT work in a WebView component!

As you suggested, I cobbled up a small project to test this (which appears and scrolls, so as you say, I have a problem somewhere), but the links at the top should move you down the page to the relevant subject, but they don't!

Looks like I'll need to use another method or let the user manually scroll?

I have attached the small project, plus I zipped the small html file and css file. if you put these into a folder and open the html file in a browser you will see how it should work.

Anyway, once again, many thanks for your expert help.

Cheers,

Malky
 

Attachments

  • TestWebView.zip
    9 KB · Views: 179
  • Files.zip
    2.6 KB · Views: 178
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try the attached code, it works!
You are too complicated :).
You don't need a ScrollView to scroll the text in the WebView.
WebView manages it on its own!
In your code I'm afraid that ScrollView consumes the Touch event.
I suspected this so I tried it without a ScrollView.

Best regards.
 

Attachments

  • TestWebView_1.zip
    8.7 KB · Views: 196
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Who de man?

Hi Klaus what can I say, brilliant!

I would never have thought of the scrollview consuming the event!

Sir, you are a gentleman and I can't thank you enough for your patience and expertise in handling this problem.

Have a good evening if you can, I will! (Haven't stopped smiling since I tested it ) :)

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Well, so much for my good evening?

I am stumped here as the small project works, I have removed everything in the large project and replaced it with the small project code.

It still won't scroll or link?????

I am going crazy with this and I know it's my own fault and is probably something sooooooo simple?

I have logged the visibility of every other view and they are all invisible.

Something is different and I can't find what?

Attached the larger project in case it sparks anything in anyone?

Malky
 

Attachments

  • homer2.zip
    88.8 KB · Views: 186
Upvote 0

klaus

Expert
Licensed User
Longtime User
Add these lines at the end of the Activity_Create routine:
B4X:
'    scvLang.Visible = False
'    scvArea.Visible = False
'    scvVillage.Visible = False
'    scvProperty.Visible = False
'    scvDescription.Visible = False
'    scvBookmarks.Visible = False
End Sub
Then uncomment one line after the other to find which ScrollView is still visible.
I don't want to give the solution but a mean to find it on your own :).
That's what I did to find the problem.

Best regards.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Damn! You magician you!

I thought I'd covered every view in the logs, JEEZ!

Hail to Klaus, (are you sure the 10 commandments are copyrighted)?

Well, my night hasn't been as pleasant as I'd hoped, which was to be just doing css stuff to make it look better, but I'll have a good sleep at least thanks to you?

What a relief at last.

Again, my sincerest thanks,

Malky
 
Upvote 0
Top