Android ViewPager: How to scrolling event beyond the end of the pager - android

I have a ViewPager which displays a bunch of pages, what I'd like to do is to detect when the user is at the last page and still attempting to scroll to the next page (of course this will not work). At that time the app should begin loading new pages and display them after loaded.
Is there any built in event that handles this event? Or how can I do it manually?

Related

Save position of scroll on webview after page closed

I am having a webview inside my application with multiple links inside. On a one page I have a list of items, but when I am going to an another page and going back to this page, my page can't restore the scroll position. How to save scroll position in this case?

android viewpager lags when swiping and loading data

I have several pages some 8 pages on my dashboard containing viewpager and all have recycler view on it. The problem is when I swipe through viewpager, both swiping and recycler view setting adapter on the page happens at the same time on same ui thread due to which swiping lags and hence there is no smooth swiping and loading experience.
Things I tried using:
1. I tried putting delay to load the data but when swiping through, the previous fragment loads data due to which the ui lags again.
2. I also used setoffscreenpagelimit but I have some 8 pages and loading all at once or even some takes time to open the dashboard.
3. I tried using addOnPageChangeListener of the viewpager. But it lags the most.
Currently i am loading data when fragment is visible i.e in setUserVisibleHint method. I want to have a smooth swiping and loading experience. Help needed.
Thanks very much.

Scrolling a ViewPager programmatically, by a small amount

I have the requirement for what is effectively two activities side by side, allowing the user to scroll from one to the other, and back. I've decided that ViewPager is probably the best way to handle this, but am open to suggestions.
When the activity loads, the left hand view is displayed. I want to indicate to the user that the other view exists, by just scrolling it a small amount to the left and back again (similar to the way it's now common to show that a sliding drawer menu exists).
I've tried a number of things but have yet failed to find a method where both the views scroll smoothly together. Another way of interpretting the requirement is saying I want to programmatically fake a user flicking the page briefly.
Try calling the method fakeDragBy(float)! According to the documentation you need to first call beginFakeDrag() to initiate it and then call endFakeDrag(). This will mantain the ViewPagers default snapping behavior, so once you've revealed the other screen is there you don't have to animate the transition back, simply call endFakeDrag and the ViewPager will correctly snap back to the last screen (As long as you haven't dragged it past the half-way mark).

Swipeable screen with content inside webView

I have a screen with recyclerView and articles list inside it. After clicking on item - i open new activity with content inside WebView (each article has own url which is displayed). I need to improve this functionality and add ability to switch between articles inside my activity with WebView by swipe movement (left - right).
That is my question: which way should i choose, make it with ViewPager or intercept swipe moves manually and refresh only content for WebView. Which way would be better for performance and more friendly user? Maybe some of you already have this experience?

Dynamically ViewPager flow of pages

I've used ViewPager to let the user flip left and right to navigate among pages of a given activity.
Is it possible to programatically control the flow of pages of the ViewPager?
For exemple:
If the user didn't fill a given EditText on the current page, I don't want him to be able to navigate to the next one.
Another case: If the user is currently on page 1 and if hi filled a given EditText with a specific value and the user flip right to left, I want him to go straight to the 5th page instead of the 2nd one.
By "flipping" you mean dragging with a finger or just using the ViewPager for animation?
If it's the former, you'll have to dynamically edit the children of the ViewPager to get the effect you want. You can override onInterceptTouchEvent() to block touch events until a page is completed.
However, I recommend disabling finger-dragging in the ViewPager (perhaps using onInterceptTouchEvent()) and then using setCurrentItem(4, true) to show the animation and navigate to a specific page. The logic you need can be implemented using buttons which will call setCurrentItem(4, true). For example, you can have a "Next->" button that is grayed out unless the form is completely completed. That will be more intuitive then the first option anyway.
Edit: 4 is just whatever child index you want to switch to.

Categories

Resources