Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewPager current position not updating correctly #11

Open
stevendesu opened this issue Apr 16, 2018 · 1 comment
Open

ViewPager current position not updating correctly #11

stevendesu opened this issue Apr 16, 2018 · 1 comment

Comments

@stevendesu
Copy link

stevendesu commented Apr 16, 2018

Update

I fixed half of my issue and made a second post (below). There's still a problem, but at least it's scrolling infinitely now

Original

I'm brand new to Android development, so forgive any terrible code or lack of understanding of simple concepts (like the difference between an Activity and a Fragment)

For my work I was asked to create a simple app with 3 screens that you could cycle between with a swipe, and on each of these screens we wanted a streaming video (same subject, different angles). Because Android supports OpenGL I know that in the worst-case scenario this is guaranteed to be possible by drawing all of the content to the screen myself, but Android had a lot of built-in UI components that seemed to make the job easier. Unfortunately I quickly learned that the ViewPager wouldn't meet my needs - as every solution online suggests you need at least 4 screens (I want 3) and their suggestion of having getCount() return Integer.MAX_VALUE means you can swipe right infinitely, but you still hit 0 if you swipe left.

Then I found this library - and the demo worked perfectly. I believe this will do everything I need. But when I tried to implement it in my project, I got the following behavior:

Load app: Displays screen A
Swipe left: Failed (hit the edge)
Swipe right: Displays screen A
Swipe right: Displays screen B
Swipe right: Displays screen C
Swipe right: Displays screen A
Swipe right: Failed (hit the edge)
Swipe left: Briefly displays screen C, then switches to screen B when the animation completes
Swipe left: Displays screen B again
Swipe left: Displays screen A
Swipe left: Displays screen C
Swipe left: Failed (hit the edge)

Here's a link to the repository where I temporarily uploaded my code (I've removed the license key for our Red5 streaming server from the code, so the video won't work -- but there's a red bar at the bottom of each screen which reads "test 1", "test 2", and "test 3" for each screen)

https://github.com/stevendesu/red5pro-tmp-repo

I'm not sure if I'm doing something wrong or if I found a bug in the library.

@stevendesu
Copy link
Author

Doing a line by line comparison between my code and the example provided, I was able to figure out at least one thing I had wrong, but it's still not behaving quite right.

Now I can swipe infinitely, but it's not always loading the right page. I'm updating the repo now with the latest code. It goes something like this:

Swipe right
2 -> 2 -> 3 -> 1 -> 3 -> 3 -> 1 -> 2 -> 3 -> 1 -> 3 -> 3 -> 1 -> 2 -> 3 -> ...
(repeating "1, 2, 3, 1, 3, 3")

Swipe left
2 -> 3 -> 3 -> 1 -> 3 -> 2 -> 1 -> 3 -> 1 -> 1 -> 3 -> 2 -> 1 -> 3 -> 1 -> 1 -> ...
(repeating "3, 2, 1, 3, 1, 1")

So it's close, but not quite right.

Also the app will randomly crash upon swiping. I don't know if it's related to this or my video streaming code.

@stevendesu stevendesu changed the title ViewPager current position not updating for me ViewPager current position not updating correctly Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant