Swipe between tabs when the layouts are the same - android

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
.

Related

Android viewpager without fragments

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.

How to implement horizontal view android studio

im trying to implement an android aplication when your activity, cointains 3 or more 'main windows' like in the image -> 'A'. 'B'.'C'. so how is posible make when you slide you touch screen change from A, to B, for example, i was thinkin in a horizontal view, and inside of each item use a relative layout, but im not sure, its my first time with this kind of problem, thanks.
Try using android ViewPager. Each ImageView would be inside a Fragment that would reside inside your Activity. Check out this example
Use Tabbed Activity template when you want to make this type of Activity. ViewPager, Adapter and tab layout will be automatically implemented for you. Just make small changes in your Adapter according to your needs and use one Fragment for one tab and you can create as many tabs as you want in an Activity.
If you want i will post an example of an Adapter as i just implemented an Activity with 3 tabs.
To get your basics strong on ViewPager, tab layout and Fragment sections adapter read out this link.

How to make tabs/sub-fragments inside a tab/fragment in Android

I have implemented an ActionBar with 3 tabs in an android app. I also used ViewPager to switch between different tabs. Every tab is defined in a fragment.
The last tab is called "Setting". I have two different settings. One is "Simple" setting, and the other one is "Advanced" setting. How can I implement these two different settings in the "Setting" tab. Should I make kind of sub-fragments or two new tabs inside the main tab which is "Setting" tab? Can I also for example create two buttons at the top, and switch between them? Or any better idea? Which solution is easier and more efficient. I'm a newbie in Android.
I want to make something like this:
Hope this help
Take SettingFragment as Host fragment
Place both buttons on top and ViewPager below buttons
Take SimpleFragment and AdvanceFragment as items in ViewPager

Making one of the actionBar tabs have a view pager

I am trying to make an app to do the following function:
I need to have an ActionBar with 3 tabs such that one of the tabs has to implement a ViewPager and the other 2 tabs has to have separate layouts.Although I know how to create an ActionBar with Tabs with fragments, I am not sure how to(or if it is even possible) to implement a ViewPager inside one of the tabs.Thanks a lot for your help.
Edit:Nvm I found the solution.You have to use nested fragments.For more information refer to
How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)

Right way to switch between tabs and change layout of the application?

I'm currently developing an application that has a tab bar, and 3
different views: the first is a master-detail, the second one a
gallery, the third is a simple webview.
I was using the TabActivity, but since Android 3.0, this class is
deprecated and Android reference
suggests to use Fragments.
I switched then to an ActionBar, with Tabs and Action
Items. Inseide the first tab item I have a layout with 2 fragments (my
master-detail view). When I switch through tabs I want that my layout
change as I described above, so I thought to hide the left fragment
(the master listview) and work only in the detail fragment.. but with
this solution I have only one main activity with a lot of fragments
attached to it, and for each fragment displayed I need to modify the
Action Item shown and handle different actions in
OnOptionItemSelected.
Is this a good way to implement this kind of
application or should I consider different solutions?
You should have a single fragment container where the fragments are replaced depending on the tab selected.
One activity and multiple fragments is the right approach.

Categories

Resources