質問

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top