I have a webview which shows an html file. When the user scrolls to the bottom of this file in webview, I want a button that was previously hidden to show up, which the user can then press to do some activity
I did something similar in iOS, where I just set the delegate to the ViewController and just set the button as visible. How do I do something similar on Android? I noticed there isn't a callback method like in iOS.
Edit: Right now, I have an activity with 2 objects: a webview containing my text, and a button which is currently invisible. I want my activity to receive a message when the webview text scrolls to the bottom, and make the button visible
[I can't comment on an answer, so leaving my comment here as a new answer]
karora's answer (the first) works very well, except that in the
method, calling
was wildly inaccurate for me. It reported a value much too small, so my listener was called when the user had only scrolled maybe a third of the way down the WebView. I used
instead, and that is perfect. Thanks to this post for that helpful hint.
try this:
To implement this, extend ScrollView and then override the onScrollChanged method (inherited from View).
I had to do this myself, in order to display an "I Agree" button once the user has scrolled to the bottom of a EULA. Lawyers, huh?
In fact when you override the WebView (rather than the ScrollView as in the answer from @JackTurky) you can call computeVerticalScrollRange() to get the height of the content, rather than getBottom() which returns the visible bottom and is not useful.
This is my comprehensive solution. As far as I can see this is all API Level 1 stuff, so it should work anywhere.
I use this to display an "I Agree" button once the user has scrolled to the bottom of the WebView, where I call it like this (in a class which "implements OnBottomReachedListener":
So when the bottom is reached (or in this case, when they get within 50 pixels of it) the "I Agree" button appears.
Loading / Visible button only when webview reached / scrolled to bottom.
Create JavaScript class :
In onCreate() :
Solutions above didn't fully work for me for the similar issue (hide button while webView is being scrolled, show after scrolling is over). The reason I wanted it to hide while scrolling is because button I want to hide is for jumping to the very bottom of webview, and when it only worked for me when webview is static, but didn't jump to bottom while view is still being scrolled. So I did the following:
added a onScrollChanged callback to overridden webView, like suggested nearby:
and in my activity class which implements OnScrollChangedCallback
UPDATED: