I want to make tabView inside a fragment. I have template from this and I want to place tabView inside one fragment. Can I implement this like implementation using activity? Any tutorial or advice about this case? Thank you.
Yes. You can use ViewPager and TabLayout
(see http://developer.android.com/training/animation/screen-slide.html)
There are two ways to add the tabs inside fragment:
TabLayout: Using this layout you can add tab in your fragment and also latest approach provided by android.
Tabhost- Using old tabhost layout. This approach is a depreciated approach. However it will also work with fragment properly.
For more reference you can check my example on GitHub-Material Navigation
Related
I am trying to build an activity that employs a ViewPager (FragmentPagerAdapter). Inside the ViewPager, I would like to open fragments programmatically. I know this can easily be achieved using FragmentTransaction.replace(int, Fragment), but I would like to use my own Fragment object. I know you can do that if you use android.app.FragmentTransaction.replace, but unfortunately from what I have found so far you can only use the support package (android.support.v4.app.FragmentTransaction) because the ViewPager originates in the support package.
Are there any workarounds/alternatives? Is there something like ViewPager in Android.view or something? Or anything that can produce tabs at the top and have it swipeable like the ViewPager (FragmentPagerAdapter)?
Really I guess the question I'm asking is if there is a way to use my own Fragment (e.g. MyFragment extends Fragment and use "MyFragment" as a fragment in a ViewPager).
Thanks for the help in advance!
use the support library and use the FragmentActivity class along with the support Fragment class android.support.v4.app.Fragment to use fragments in your viewpager
you will have to change all your fragments you want to use in the viewpager over to the support fragment
I am using Fragment for Slider menu in Android. Source : Android Slider Menu
Now, I want to add ViewPager inside first Fragment which is Home. So I found some tutorials for it. But all are using FragmentActivity so I am not able to call it inside Fragment.
Please help me regarding this.
I think this should help you out.The key is to use Nested Fragment calls instead of a calling an Activity that uses the FragmentActivity.Find more about Nested Fragment calls here Please check out this question and see how this is implemented.
Android: Viewpager inside a fragment of Navigation Drawer
I know my questions sounds like a tongue twister. Anyway I wanted to implement it but I don't have any idea on how to do it. I already know on how to use a FragmentActivity and add the TabHost for it but now what I have is a fragment that should also contain a Tab which also has a fragment. To give it a more detail here's what I wanted to implement:
What I tried so far is to Create a new FragmentActivity which will be contained inside a FragmentActivity and I got a ClassCastException. Any ideas on how can I achieve this?
Using a newer version of the Support Library, or native Fragments if you only care about Honeycomb, you can add Fragments as children of other fragments.
You can call getChildFragmentmanager() inside one of your top level Fragments and add your child Fragments there.
I need to create a TabWidget inside a Fragment. It should look like as in the attached image. The content of each Tab should be in a separate Fragment...
I think you just need to visit developer.android
Think I have an activity with some layouts, I want to know is it possible to use layouts in activity for thats activity ViewPager items ?
is it possible ? if so , how ?
thanks
You should use a ViewPager, where each page holds a Fragment. This sample code explains how it can be done.
If you want your application to support pre-Honeycomb devices, you'll want to use the ViewPager and Fragments from the Android Support Package.
You can use viewpager with fragment. See the sample code below. I think this will be helpful for you.
http://developer.android.com/resources/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentPagerSupport.html