Is it possible to use android.app.Fragment with FragmentStatePagerAdapter - android

How would I use android.app.Fragment; inside FragmentStatePagerAdapter
It only supports returning: android.support.v4.app.Fragment. An existing fragment I am using inherits from RxFragment which doesn't use the support library fragment.

You can't.
FragmentStatePagerAdapter and FragmentPagerAdapter are part of the support library, and only support the support Fragments.
If you really want to do this, you could copy the source for those classes and replace the support Fragment imports with framework Fragment imports.

You can use android.app.Fragment if you use android.support.v13.app.FragmentStatePagerAdapter from the v13 Support Library. See this answer from #brillenheini

Related

getChildFragmentManager in a fragment in level API 17 < [duplicate]

I am trying to use getChildFragmentManager() method on api 14, but of course I am getting error. Is there anyway to use this method on lower apis.
Thanks
To use nested fragments on API Level 16 and below, you need to use the fragments backport from the support-v4 or support-v13 portion of the Android Support package. This, in turn, requires you to inherit from FragmentActivity and have your fragments inherit from android.support.v4.app.Fragment. Then, you can call getChildFragmentManager() to use nested fragments.
To someone that appeared here by a search on Google
I was having a similar problem using DialogFragment
The problem was because I was importing android.app.DialogFragment instead of android.support.v4.app.DialogFragment
DialogFragment or not, be sure that you are importing the right libs :)

Add library in android Studio

Its very hard to describe my problem but I'll do my best <<
when I want to make a ViewPager in MainActivity , I go to xml then :
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
/>
then I make an Adapter
public class MyAdapter extends FragmentPagerAdapter
here , I need to import
android.support.v13.app.FragmentPagerAdapter;
the QUESTION is ;
is there any problem when I use v4 , v13 on one application
note : I add the v13 library and make it as (provided)
On one hand you can use both v4 and v13 support packages. Sometimes you have to.
For example android.support.v13.app.FragmentPagerAdapter and android.support.v4.app.FragmentPagerAdapter are similar but not identical : they don't use the same kind of fragments (native android.app.Fragment vs support android.support.v4.app.Fragment).
So if you want to use a ViewPager with native fragment you have to extend the v13 FragmentPagerAdapter and set it on the ViewPager (v4, there is only one). Of course this will only work on v13+ devices.
On the other hand you don't have to declare both library : the v13 support lib includes the v4, adding something like
compile "com.android.support:support-v13:23.1.1"
in your build.gradle gives you access to both v4 an v13 support classes.
By the way, see Fragment or Support Fragment for more details about native vs support fragments.
Edit: There shouldn't be a problem using both, just don't set it as provided. Use compile as the classes are not provided by the system.

getChildFragmentManager for non support fragment as nested fragment

I'm using an nested fragment which is of class Fragment, as opposed to SupportFragment (v4).
I should use getChildSupportManager to handle this properly, but that suspects v4 support fragments, and I have a regular Fragment (which I can't change, it comes from a library).
How would I be able to solve this?
I should use getChildSupportManager to handle this properly, but that suspects v4 support fragments
AFAIK, there is no getChildSupportManager() method in Android. There is getChildFragmentManager().
If you are using getChildFragmentManager() from a FragmentActivity, you need to give it a fragment from the Android Support package backport (android.support.v4.app.Fragment). If you are using getChildFragmentManager() from a regular Activity on API Level 17+, you need to give it a native fragment (android.app.Fragment).
I have a regular Fragment (which I can't change, it comes from a library).
Then set your minSdkVersion to 17 and use Activity instead of FragmentActivity.

Android getChildFragmentManager() level API < 17

I am trying to use getChildFragmentManager() method on api 14, but of course I am getting error. Is there anyway to use this method on lower apis.
Thanks
To use nested fragments on API Level 16 and below, you need to use the fragments backport from the support-v4 or support-v13 portion of the Android Support package. This, in turn, requires you to inherit from FragmentActivity and have your fragments inherit from android.support.v4.app.Fragment. Then, you can call getChildFragmentManager() to use nested fragments.
To someone that appeared here by a search on Google
I was having a similar problem using DialogFragment
The problem was because I was importing android.app.DialogFragment instead of android.support.v4.app.DialogFragment
DialogFragment or not, be sure that you are importing the right libs :)

Android: TabManager class can't be resolved, inheriting from FragmentActivity

I am following the example here
http://developer.android.com/reference/android/app/TabActivity.html
creating tabs using fragments and in the tutorial it uses TabManager but on my version it says it cannot be resolved.
I am using minsdk set to 14 and targetsdk set to 15.
I don't wish to use the backward compatible support.
Any ideas which package it is in?
Eclipse doesn't provide me any help, only asks me to create the class TabManager.
Thanks in advance
TabManager is for the compatibility fragment tabs, not for the 3.0+ fragment tabs. That's why it can't be resolved.
The tutorial here shows how to create fragment tabs in 3.0+:
http://developer.android.com/reference/android/app/ActionBar.html#newTab()
Also, you don't have to inherit from FragmentActivity starting in Honeycomb unless you want backwards compatibility. You can just inherit from Activity and Fragment will be supported.

Categories

Resources