Alternative to FragmentStatePagerAdapter [duplicate] - android

I want to find a replacement to the FragmentStatePagerAdapter + PagerFragment as we all know the FragmentStatePagerAdapter is still broken up to this day. There have been a bunch of attempts on github and by myself to make something that mimics the functionality of the FragmentStatePagerAdapter, except all of them seem to have extremely complicated logic with bugs that seem impossible to debug, e.g. https://gist.github.com/ypresto/8c13cb88a0973d071a64.
The core functionality of my application needs to be able to display fragments/views dynamically, e.g. a photo carousel with interleaving ads as the user swipes from left to right and vice versa. And we can dynamically remove or add or manage stuff from/to the adapter.
I've been thinking of potentially making a horizontal recycler view with the view taking up the full screen, and having a bunch of listeners that make the view "center" as the user swipes so that it has a view pager feel to it. But I'm not 100% convinced that this is the best solution to solving this issue. I was wondering if anyone has ever come across issues with FragmentStatePagerAdapter, and has found a good solution to workaround.
Thanks for the help!

Related

Firebase with viewpager

I am currently building an app using firebase.
I have an activity in which the background and UI are the same, but the page has only the contents that change inside according to the date.
It`s kind of some diary app.
I am worried about whether I need to ViewPager or not to use ViewPager, but if I have saved it somewhere and clicked on that date, I need to display the contents with setText(). I'm not sure about that how to do more optimization.
And when I scroll horizontally across the screen, I want to see the pages change with swipe-animation. Do I have to use viewPager? I mean I use one page but I want to give a fake animation effect as the page looks. If this helps optimally.
Anyway, So I'm looking for an example that uses viewPager with firebase recycler-view, but it's a bit hard to find. Is it better to use a fragment? with this?
Optimization has been troubling for weeks on issues.
I have a lot of questions, but I would like to hear good advice on these things.
I would appreciate it if you could explain it slowly and easily.
Thank you very much for reading.
Page has only the contents that change inside according to the date.It`s kind of some diary app. I am worried about whether I need to
ViewPager or not to use ViewPager?
Yes, Viewpager with FragmentStatePagerAdapter is a good choice here, as there may be many dates in your case with its own content.
Check out the below link, it explained very well how any why to use viewpager with tabLayout.
https://guides.codepath.com/android/google-play-style-tabs-using-tablayout
And when I scroll horizontally across the screen, I want to see the
pages change with swipe-animation. Do I have to use viewPager?
For animation between the page swipes, you can use pageTransformer.
Checkout this
https://developer.android.com/training/animation/screen-slide.html
and
https://medium.com/#BashaChris/the-android-viewpager-has-become-a-fairly-popular-component-among-android-apps-its-simple-6bca403b16d4

What is the best and most practical way to mimic the "Menu button" behavior / OR / card stack custom view

I need to create a new view that will contain a stack of cards, similar to what the Menu softkey does. After googling and trying things out, I saw that the menu button relies on a com.android.internal.view.menu.IconMenuItemView class, however - i really just need a stack of cards that respond to touches, so i can implement my logic in their onTouch or a custom onTouchListener.
What I really need is this - a displayable stack of cards, so that they're on top of each other, fully displaying only one card and displaying the header of the previous few cards, and potentially the header of the next card.
I have the CardView all setup. I'm kinda having problems properly implementing my CardStackView due to the fact that CardStackView extends ScrollView hit a brickwall due to the fact that ScrollView simply steals all touch events even when i use scroll.requestDisallowInterceptTouchEvent(true). I've also tried CardStackview extends FrameLayout and tried keeping everything in check myself, however i somewhat ran into layouting issues there (all cards were simply "one card" meaning they all positioned themselves on top of the layout, AS WELL as not responding to touch events).
Now, i'm really looking for a solution or hints to how I could mimic the menu button (it actually shows current/recent activities as scrollable cards) as a custom View. I'm down to my almost-last attempt at basing my wrapper view as CardStackView extends ViewGroup and trying that.
Guys (and gals) - please help, i'm running out of options here while i'm not really really working on implementing the view, rather than trying out different bases i could use so i'd have a bit less work to do. I'm down to ViewGroup :/ I would really like it if I don't have to go as low as CardStackView extends View and re-inventing the wheel and doing everything myself.
So, borrowing or copypasting or replicating the "Menu button press" behaviour/look&feel would really help me out, since it really looks like what I'm looking for and my objective. Once i get cards stacked like that, i can fully devote myself to implementing the proper logic and tweaks either in the onTouch() or wherever needed really.
I hope I explained the problem clearly, however if I did not - feel free to ask more via comments and I will respond while trying my luck with the current ViewGroup idea. CardView extends LinearLayout, while for CardStackView (which is a compound control from what i've read online) I've tried extending ScrollView, FrameLayout and am trying with ViewGroup :/
Please men (and women), help a fellow dev out :)
EDIT1:
After receiving the "you need to be more concise" comment, i figured to better explain the situation.
I'm trying to create a custom view that looks and behaves closely like the one you see when you press the menu buttons (when the activities are all stacked in a stack of cards). The cards need to be clickable, and draggable - meaning they need to respond to touch events. The best explanation I had was to compare it with the "menu button" example.
concise problem - what to base the "stack of cards" view on? ViewGroup? Something better? I have no real problem posting the full code here like i did for my "edittext-on-demand" view, but for now i'm just looking for some hints, tips and pointers on how to best tackle the problem. I've wasted two days on it already.
EDIT2: The CardStackView will need to dynamically inflate and add other CardViews (custom view)

Alternatives to android.widget.Gallery (not the Gallery app)

Apology if this has been asked before, but I've tried googling the topic without any good result. Basically I'm trying to find a replacement for Gallery widget which Google has decided to deprecate. So far I have the following candidates:
ViewPager. Unfortunately (as far as I know), you can only display one View at a time. I know someone has posted a workaround for this here: https://gist.github.com/devunwired/8cbe094bb7a783e37ad1. But I'm having problem with this approach. On my phone, three images are shown (horizontally). The most left & the most right are static, while the middle one is scrollable (like what ViewPager should do). i.e. the most left & most right image doesnt scroll as I scroll the ViewPager. So I have to turn down this solution.
GridView. Seems good, but it seems like GridView is designed to be scrollable horizontally & vertically. I just want one row, and scroll horizontally. As far as I know, Gallery is not designed with this in mind.
HorizontalScrollView. Another one that Google has suggested in the Javadocs (apart from ViewPager). Seems like a good one to use, but... if i understand it correctly, using this approach all the contents are going to be instantiated up front. There is no lazy loading..
So I'm puzzled right here. Seems like the best solution is to either use ViewPager with only one View at a time (undesirable for what I want), or stick with Gallery.
What do people think??
Thanks in advance!
android.support.v4.view.ViewPager is the definitive answer.
You can display any number of pages (Views), it all depends on the PagerAdapter. It has a method .getPageWidth(position), which gets called for each page. If it returns 0.5, for example, the page will only be half the width of the ViewPager.
Don't stick with Gallery, as it has memory leak issues.

Swipe Indication for user Android

Suppose I have a ListView displaying exactly 10 rows that is not intended to scroll.
When the user swipes, the next list of 10 rows would be displayed. The bottom of the ListView would say something like "page 2 of 3".
How can I indicate to users that they should swipe to get the next page?
A page indicator might be helpful like you said. I view-pager may be another option. In that case I would use: http://viewpagerindicator.com/
I think you are best off rolling your own solution using a ScrollView and/or a ViewPager
According to a GoogleIO presentation about ListViews, they are coded with many "behind-the-scenes" tricks in order to optimize performance.
When you start trying to modify how they work, then you end up with a complex widget that doesn't make use of its own complexity and optimizations.
Some type of vertical view pager could be good for what you see though.
Reference: http://www.youtube.com/watch?v=wDBM6wVEO70

ViewPager flips instead of scrolls when paging through onClick

I have implemented a ViewPager in my app, and aside from the swipe paging, I have buttons for "Next" and "Back", with a simple onClick method with the only line being a setCurrentItem for the ViewPager.
While the paging animation is completely smooth during swiping, it is more or less instantaneous (just flips instead of scrolling) when I click Next or Back. There is no visible "scrolling" motion, or sometimes barely visible, however not even close to smooth. It does not hurt the usability of the app in any way, since the transition still happens immediately, but visually it looks a lot less appealing, and the user experience suffers.
Now, I suspect it has something to do with the app drawing the next View and therefore "skipping" the animation. My instantiateItem uses LayoutInflater and a simple switch statement to inflate each view (4 pages at most), and I am loading custom ListViews inside each case in the switch statement. The custom ListViews are at most 3 items long, with a TextView and an ImageView in each row (ImageView resource is 5kb in size). To me it seems this amount of objects should not be reason enough to slow down the paging animation.
Aside from that, I also have a custom background assigned to my app in styles.xml, and this is the background used through every activity (160kb in size).
Those are the only things that I think could be slowing down the app, since the onClick method contains only one line (setCurrentItem), so nothing aside from going to the next view is happening in the app, and the instantiateItem is the simplest implementation of the method possible that I know of.
Things I've tried:
Setting the ViewPager's setOffScreenPageLimit to 4, which I thought would pre-load the views and eliminate any loading in between paging, but in the end setting it to 0 seemed to make the thing slightly more likely to show at least a frame of animation
Optimizing the custom ListViews by using convertView to reuse old views, while it did result in more of the animation being shown, it still wasn't completely smooth, varying from "almost perfect animation" to "instant flip"
Removing the custom background, which together with the above two fixes lead to an almost good enough solution, but still resulted in flips every few steps.
The tinkering described above leads me to believe it has something to do with the views being loaded, but I've not found a good solution for pre-loading these to the desirable effect.
Knowing my newbie programming skills, I know there is a sure fire way to solve this without resorting to gimping the design of the app itself, but reading through the documentation, Stack Overflow questions, Googling for advice, I've just ran out of places to look to.
To sum up this probably too verbally descriptive post my main questions are:
Is there a way to ensure the animation of the ViewPager is executed smoothly? A separate thread perhaps? As I understand though, UI stuff should only be on the main thread, where it already is, and nothing else aside from the view loading is executed anywhere in the code when paging.
Should I be using a different way to load the pages? Would Fragments help?
Thank you for any advice.
ps. The lack of code is due to the methods in question being the most basic implementations possible, but I will provide the code if necessary.

Categories

Resources