i'm displaying a web page in android webview. and i want to trigger a message when the user reaches end of page while scrolling. how can i do that? TIA
One way is we can write custom MyWebView class that extends WebView and then we can use the function called computeHorizontalScrollRange() orcomputeVirticalScrollRange() to get the scroll range of webview.
AFAIK, I don't think there is any event that triggers this. But here's one way - you will have to try and see if it works though. Have a ListView with two rows - one having the WebViewClient and another just an ordinary TextView - You could use something like SackOfViewsAdapter for this.
In your adapter's getView(), when the function is called to display the bottom TextView, that's your cue on the user having scrolled down.
Related
I want to implement functionality where a listview loads a set number of views, but at the end of the scrolling it has a spinner in that view, while it loads more views
the official android twitter app has something like this, where it shows you old messages from your timeline but at the bottom of the list it will load more after running a spinner. you can still scroll up and down while this thread is happening without breaking anything
how would this be done? insight appreciated
i think by spinner u mean blocking screen ?
anyways what u need is pretty common, just search for listview implementation in android
here is one of the link i still had:
http://blog.zjor.ru/2010/12/loading-list-data-asynchronously-in.html
also check this if u really want to go to that extent ;)
https://github.com/commonsguy/cwac-endless
basically, it would probably be something like:
Load some data (use a limit)
When you enter the bindView of your last element, change your limit (may be by joining the cursor to another one)
I have a Edittext, a button and a ListView in my activity. Now when any of the options on listview are selected i want to replace everything by a webview and if the user presses back i want to come back to the original view.
How do i do this?
I looked at View flipper but that is mostly used if you switch between views a lot, also is it a good idea to use webview with viewflipper.
You could use the visiblity of the views, so setup a webview that fills the screen then set its visibility to gone in your xml, then when you want to display it use myView.setVisibility(View.VISIBLE); in your code to display the webview, it would probable be a good idead to make your buttons etc invisible using myView.setVisibility(View.GONE);
It would however be easier just to setup another activity with your webview in and just start that activity when required.
In view method of item Listener of your code do something like this...
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("Web link here"));
and you are done with it...
Or please post your code so I can help you in better manner...
i am using a list view in which i want to directly shift to particular position when i run my code. i m using listview.smoothScrollToPosition(22) which will show the scrolling effect.. which i do not want to show. i want to directly display 22 position of list view.
i used other methods like listview.setselection(), listview.scrollTo() which doesnt work??
Kindly, help me out
Thank you
setSelection is what I use in a public domain app I develop. You can read the code here. It scrolls the ListView to the position I specify.
Perhaps you could post your code if this method isn't working for you?
I've got a ListActivity that displays WebViews.
There is a menu option to copy text that will call this on visible WebViews.
Everything works except for one thing. I can't perform text selection in vertical direction as ListView consumes corresponding MotionEvents for it's own scrolling.
I've tried this:
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (webViewsInTextSelectionMode) {
bypassEventToWebViews(ev);
return true;
} else {
return super.dispatchTouchEvent(ev);
}
}
Which will block scrolling but will also pass unadjusted MotionEvent coordinates to a WebView.
Is there a way to correctly prevent ListView from scrolling in this case?
I've got a ListActivity that displays WebViews.
That is not a good idea. WebView and ListView will compete for motion events. Putting scrolling things in scrolling things is rarely advisable in Android, particularly when they can scroll in the same direction (in this case, up and down).
There is a menu option to copy text that will call this on visible WebViews.
If you mean the accepted answer on that question, that is also not a good idea. I am dubious about the other answer, but at least it's not a bad idea prima facia.
Everything works except for one thing. I can't perform text selection in vertical direction as ListView consumes corresponding MotionEvents for it's own scrolling.
My point exactly.
Is there a way to correctly prevent ListView from scrolling in this case?
I would focus instead on getting rid of the WebViews, replacing them with TextView and Html.fromHtml(). Or, get rid of the ListView, using a single WebView to render your consolidated content.
This is a complete shot in the dark and most likely won't work but probably worth a try. You can try calling ViewParent#requestDisallowInterceptTouchEvent on the parent ListView inside of the ViewGroup containing your WebView. You'll have to call that every time there is a down motion event for the duration of the text selection. This is because the flag is reset on a up/cancel motion event.
If that doesn't work you'll probably have to create your own copy of ListView and modify it appropriately. This isn't too daunting, you'll have to copy all classes in the class hierarchy back to AdapterView and fix the copied AdapterView class (mainly use of private/package level member variables that have protected/public accessors functions).
I update the html in a webView using loadData() followed by a reload(). I get the new data to display but the scroll of the page has not updated. I want to keep the view of the page at the bottom. I can wait a long time and it still doesn't update. Once I click the webView the scroll bars adjust and I can drag to the bottom of the page and see the new text.
Things I have tried:
- multiple settings and calls in onPageFinished(). None worked because the getContentHeight() hasn't changed yet. I have also tried to scrollTo(100 + getContentHeight) and that doesn't work.
- pageDown(true)
calling requestLayout() after reload()
browser.requestFocusFromTouch() - still no good, thinking i could simulate my click.
adding a few br tags. This worked a bit, but the number of br's has to equal the number of lines of new text. Since the number of new lines is not something that can be exactly determined based on orientation and screen variables it's not a good fix.
Any ideas? TIA
If you want the webview to be scrolled to the bottom after it's finished loading, I found I had to use pageDown(true) in onNewPicture. (I believe that's the event fired when a view is finished drawing.)
So the code looks something like
webView.setPictureListener( new WebView.PictureListener() {
public void onNewPicture(WebView view, Picture picture) {
webView.pageDown(true);
}
}
Using pageDown has the unfortunate problem of visibly scrolling the page; I'm having problems finding any other way to jump to the bottom of the webView, found this question while looking for a solution! (I haven't tried reaching inside the WebView and using javascript yet, though.)