Material design sliding tabs not accessing more than two fragments - android

I have designed material design sliding tabs in android. I have added 3 tabs and want to change the UI at runtime from main activity but only 2 fragments has been instantiated and accessed except the 3rd. how to get the 3rd fragment to be instantiated and accessed?

By default the offscreenPageLimit for the ViewPager is 1. so, the ViewPager loads and extra one page from left and one page from right (total 3 pages).
You can change that by calling ViewPager.setOffscreenPageLimit(2);
this will load a 2 pages from each side (total 5 pages).

Refer this
Implement Sliding Tab Layout

Related

Second set of tabs in an Android fragment

I want to add a second row of tabs to my Android application on the second fragment accessed from the ActionBar tabs.
Tab 1 shows fragment 1.
Tab 2 shows fragment 2 but I would like fragment 2 to have a second row of tabs so it will show fragment a or b.
But it seems like fragments within fragments cannot be done and an ActionBar submenu can't be switched on or off. I have also tried with a FragmentStatePagerAdapter with a TabHost and a ViewPager which displays the tabs fine but does not display the fragments. Is there any other way to do this?
If you know the new Design Support Library ....
In your second fragment you can use TabLayout introduced in design support library 22 . Which is same as Actionbar tabs.
So just add the TabLayout in your second fragment XML.
And TabLayout has a method setUpWithViewPager(). So you can easily setup your tabs.
I hope it helps you.
here is the reference http://android-developers.blogspot.in/2015/05/android-design-support-library.html

Android - Refresh/restart all tab fragments when selected/reselected

once again, I am following this tutorial: androidhive - tab layout with swipe able views . All 3 fragment tabs are loaded with different information and logic and layouts. I would like to refresh each fragment when their tabs have been clicked as it auto loads the fragments from start as it uses the view pager. Is there any simplest way out that I could load only a/1 fragment using view pager? Or to reload the fragments? Thanks for your help!
Try to add this to your viewpager:
MY_VIEWPAGER.setOffscreenPageLimit(0);
Check out the documentation.
Pages beyond this limit will be recreated from the adapter when needed.
The limit of 0 will cause a recreation of the fragment when you open a tab.

How to create 2 nested tabs within a tab in android?

I have 3 tabs basically and on clicking one of those I want to display 2 more tabs which is like nested tabs. How can I achieve this in android? I just added 3 tabs in an activity and in one tab activity I again added 2 more tabs. But this is giving me error.
Please anybody have any other idea share it and help me out,thanks in advance.
That's not a good idea. How users are supposed to know which tabs would respond to a swipe action? Multi-level tabs are confusing. You should use drop down navigation or a navigation drawer instead of top-level tabs.

Android-Implement swipe tabs in swipe tabs

I have three horizontal tabs A, B and C. They have been implemented using FragmentPagerAdapter. Is there a way I can again implement horizontal swipe tabs in each tab.
Tab A
-- Tab 1
-- Tab 2
-- Tab 3
Tab B
-- Tab 1
-- Tab 1
-- Tab 1
and so on.
Do you mean you want nested tabs? If so, I would suggest looking into the documentation for FragmentStatePagerAdapter
Assuming you have fragments set up for each tab, embed a FragmentStatePagerAdapter within the existing FragmentPagerAdapter.
Copy and convert your activity to a Fragment and embed it in the existing activity.
WARNING!
This design is HIGHLY warned against by Google! I would not suggest using it.
Anyway, hope it helps.

Add/Remove Tab and its content from tabhost

I have nine tabs(say 0 to 8), displaying only five tabs on screen.
The five tabs will be 0 to 3 of those nine tabs and fifth tab will be MORE Tab.
MORE tab will show Activity with GridView showing Image+Title of remaining nine tabs(say 4 to 8).
Now on click of any item(Image+Title) in GridView will replace the MORE Tab Image+Title and its content/activity with its respective activity.
I am able to replace the tab indicators(Image+Title) but struggling on replace its respective content/activity.
As on other similar thread they had suggested to use clearAllTabs and add/recreate require tabs again. But i feel clearing all tabs just to replace one tab is heavy.
I am using the TabActivity with Intents. As i know TabActivity is deprecated by its old app initially it had only 5 tabs but now requirement is to add few more tabs.
Need your help to implement this. If it not possible with TabActivity, then switching to fragment tabs does it help me?
I trying to implemtent this Image
I would recommend fragments for sure. I've used TabHost in the past and it was very problematic.
You can simply have Button at the top that control the visibility of the fragment below. With this way, you'll even be able to add transitions.
This link give a little more information on that topic. Separate Back Stack for each tab in Android using Fragments

Categories

Resources