Display fragment viewpager within a fragment

use AsyncTask to set the adapter for viewPager. It works for me. The asyncTask is to make the original fragment complete it’s transition. and then we proceed with viewPager fragments, basically to avoid recursion. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.team_card_master, container, false); mViewPager = (ViewPager)mView.findViewById(R.id.team_card_master_view_pager); final Button button … Read more

How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)

Assuming you have created the correct xml layouts. It is now very simple to display fragments in a ViewPager that is hosted by another Fragment. The following is a parent fragment that displays child fragments: class ParentViewPagerFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val root = inflater.inflate(R.layout.fragment_parent_viewpager, container, … Read more

Dynamically changing the fragments inside a fragment tab host?

Basic concept- We can achieve this by creating a container. Each tab will be assigned with a specific container. Now when we need a new fragment then we will replace same using this container. Kindly follow undermentioned code step by step to have better understanding. Step-1: Create Tabs for your app. Say “Home.java”. It will … Read more

Getting the error “Java.lang.IllegalStateException Activity has been destroyed” when using tabs with ViewPager

This seems to be a bug in the newly added support for nested fragments. Basically, the child FragmentManager ends up with a broken internal state when it is detached from the activity. A short-term workaround that fixed it for me is to add the following to onDetach() of every Fragment which you call getChildFragmentManager() on: … Read more

Fragments within Fragments

Nested fragments are not currently supported. Trying to put a fragment within the UI of another fragment will result in undefined and likely broken behavior. Update: Nested fragments are supported as of Android 4.2 (and Android Support Library rev 11) : http://developer.android.com/about/versions/android-4.2.html#NestedFragments NOTE (as per this docs): “Note: You cannot inflate a layout into a … Read more