Android viewpager without fragments - android

I want to have a ViewPager and a TabLayout, to display a graph. The TabLayout has tabs for each month, to show the different data in the graph, and when I change the tab, the dataset changes. All the views shown in the viewpager have the same xml layout (containing the graph object), and the changes to the graph have to be done programatically (Adding the dataset to the graph). Using fragments makes no sense, because I'd need 10+ fragments which all use the same layout. How could I implement this efficiently?
If its tricky to understand, I could add some code to show my issue. I'm using GraphView library for the graphs, if it helps.

1.Create your own Custom Viewer pager. and set to a adapter. Adapter will inflate and you can prefill the data based on your needs. Refer blog here
Use fragments to achieve it.
use AppIntro lib - which in turn uses the fragments. AppIntro
If you dont want to use fragments, create your own custom viewpager without using fragments.

Related

How to combine two activities together to use it as a single feature?

I am stuck with a problem where I have designed a tab layout that I have used as a library in the current project which has a Recycler View. I want to show the tab layout on top and the recycler view under the tab layout.
For reference in Whatsapp, there is tab layout under which there is a recycler view that shows all the messages.
Problem is that I am confused about how to combine both activities together so the user can use the tab layout.
If anyone knows any solution please help!!
Use single-activity pattern. This pattern means that you need to use Fragments in a single activity (MainActivity, etc). Additional tip, you can use ViewPager2 with TabLayout for your Fragments.
Activities can't be composed into one, cause it designed so.

Swipe between tabs when the layouts are the same

I want to add two tabs to my Android app.
Tab 1: To do tasks
Tab 2: Done tasks
The layout in both views is the same (the only thing changing is the data shown). It's a gridlayout with cardviews.
How can I implement the tab/swipe action that changes from one to another being both the same .xml?
Android documentation is outdated and many of the methods used here are deprecated.
You can use viewPager and tabLayout for that swipefeature and call your fragments through custom adapter by extanding FragmentPagerAdapter in that
.

How is it possible to use a single fragment in place of multiple fragments to load same format contents inside of ViewPager

I am facing a situation as of few days now. I intend to create an activity where there is a TabLayout and a ViewPager.
The tabs in TabLayout corresponds with the fragments/slides in the ViewPager.
Now as of now, each fragment contains the same format,i.e., two TextViews, one under the other, populated with the strings softcoded in string.xml
But this resulted in the creation of too much xml files for the fragments used inside ViewPager.
So I was thinking if it's possible to use only one fragment inside the ViewPager and then programmatically set the strings for those two TextViews in the fragment, that changes each time w.r.t. click on another tab or sliding on the ViewPager area.
This will lessen the no. of fragments to only one, in turn cutting the time to create it and increase the overall performance of the app in which it will be present.
So any insightful help, suggestion, or walkthrough on how to implement this concept - any help on how to do this will be highly appreciated.
You can certainly do that. If you're using FragmentStatePagerAdapter, just initiate the same fragment with different arguments supplied according to it's position and then in fragment check for those arguments and make changes accordingly.

What is the convention for using Fragments and views in a ViewPager?

I have a ViewPager and I want to use implement fragments for it, but I don't know what is the best way to do it, should I have multiple instances of a fragment with different views or should I have multiple fragments with their own views?
Edit:
What should I do when I have different layouts, exactly?
Check out the code on my git.
This includes infinite scrolling along with header that moves along scrolling and clickable pagerview pager with fragments with listview
You just have to replace the fragmented layout to however you want.
Im using this for my own sns and its very speedy. Make sure you have asynctask for any heavy loading

How to display different layouts with the ViewPager?

In Xamarin, I currently have two different activities and I would like to combine these together and use a ViewPager.
One activity uses the following content view: SetContentView(Resource.Layout.MapWithOverlayLayout);
The second activity uses the following content view: SetContentView(Resource.Layout.HomeScreen);
Can I please have some help to code a simple ViewPager that can add the two above content views into a ViewPager and then show each of these content views via code?
Thanks in advance
For a ViewPager, you will need Fragments instead of Activities.
Here is how to implement a ViewPager with Fragments and different layouts: How to implement a ViewPager with different Fragments / Layouts
The basic idea is that you create a Fragment for every layout you have, and then inside your FragmentPagerAdapter, load the correct Fragment depending on which page you are currently on.
This is how I am doing it in my other post and sorry about not posting the same code here.
Take a look at those links. It will help for sure.
Android:How to create different view in ViewPager?
Its a pretty simple implementation. You can define your own layouts and then use it in the view pager.
Here's my other post where you can get what you want to achieve:
How to use swipe gesture in a view pager's page with android?
Hope this helps..:)

Categories

Resources