Pass ViewPager with ListView - android

I need help for how can I implement this if possible.
I want to use ListView to view a ViewPager and then go through them.
What I mean here is, when I click on ListView item0, thus open ViewPager item(in my case fragment)0 and so on. And if I opened ViewPager0 and swaps to 1,2,n So let the ListView know in which ViewPager I am (in order to avoid duplication or crashing).
Thank in advance.

Related

What is the correct way to approach ViewPager and Fragments when number of fragments are more than 50 but each of them has same layout and methods?

I am making an app which has a navigation drawer. This navigation drawer has 50 menu items. These items have the same layout, same activity but different data.
I want to implement ViewPager in my app so that the user could swipe left and right (manually and automatically).
Issue: I am facing an issue of how to implement this. The activity (for these menu items) has its own methods and functionality. A ViewPager can slide fragments but my issue is that since all of these menu items have the same layout and functionality then it would be much better to use one fragment whose data change with swipes for each menu items.
I don't know how to approach this. Please guide me.
You can do it by using a recycleView,and you will need an arrayAdapter which will help you adapt the data accordingly and you will need to have a separate class that will have all the data you want, you can also have different constructor in that class. You can check this to know more https://www.codexpedia.com/android/a-very-simple-example-of-android-recyclerview/

How To Open Another Activity By Swiping

I am A beginner at android. I have created an app which loads news from JSON to recycler view. I want to open an activity when the user swipes from left to right. I tried different methods but it doesn't work for me. Please help.
You have to create an activity first and put a view pager in it and switch between fragments : ( its better to use fragments at this kind of situations, u can swipe between ur fragments by using android view pager )
Here is a great link that gonna help you :
https://medium.com/#kyroschow/how-to-use-viewpager-for-navigating-between-fragments-with-tablayout-a28b4cf92c42
Have a good day
The better option is to use one Activity & other Fragments. And then use Viewpager for swipe between fragments. Follow below link:
https://developer.android.com/training/animation/screen-slide

ViewPager or RecyclerView with fragments?

I am a little bit confused on how should I approach this particular case of doing some swipes between fragments.
So yea, I asked ViewPager or RecyclerView, because these 2 are my only options, if anyone can come up with a better idea, it is really welcome.
The flow is the following, I have a Main Timeline(ListView), each item of it opens a fragment with details about it. What I would actually want to do is to swipe between these full screen fragments without going back to MTL and open another item of the list.
You would ask me what I tried, well:
RecyclerView - HORIZONTALLY oriented as a root of the fragment, and each item of this RV had the details of each event. The problem with this is that it gets really buggy because I have a huge logic inside each item(like, another RV - horizontally , a PagerView also horizontally to swipe between images (or a youtube frame that is being played if is the case. Plus a lot of other stuff in this, so the logic of parent RV inside the onBindViewHolder() is really tricky.
Would be better to use a PagerView with fragments(since I have the DetailsFragment kind of ready) ? The problem here is that I need a certain number of swipes, right ?
Go with viewpager.
Because creating fragments inside recyclerview causes recyclerview performs to slow down.Also to create fragments in onBindViewHolder() dynamically every time you need different unique id of frame layout to load which will be tough to generate.
For more information on why recycler view is bad idea to load fragments check this.
Fragment replacing in RecyclerView item
Also try to use the ViewPager with an implementation of FragmentStatePagerAdapter. The adapter will optimize the memory usage by destroying fragments that are not visible at a given moment.
Check the documentation for details and code sample.
https://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html

How can I implement tabs with RecyclerView

Currently I have a RecyclerView which upon creation is populated by a list of movies stored in an SQLite DB. Every movie has a genre that can be set by the end user.
I want to be able to set-up dynamic tabs for each genre that users can swipe through for easier access as the dataset grows. I was just at a loss for where to start. Any help is appreciated. Thank you.
TabLayout is where you should start.
You can use addTab() for dynamic tab creation.
TabLayout is made to work well with ViewPager. When you use the setupWithViewPager() method, the two are set up with corresponding event listeners, so that swiping in the ViewPager sets the tab active, and selecting the tab goes to that tab's page in the ViewPager.
I think you can start with ViewPager and use RecyclerView in its fragments.

How to save state of page in viewpager in multiple viewpager inside listview?

i created multiple Viewpager inside listview but when i scroll my viewpager page state is change i dont know how to save state of all viewpager inside in listview.please help me.
thank you
If I understood it correctly you need to check this out:
http://github.com/hanks-zyh/ViewPager-Listview-item-Viewpager-

Categories

Resources