The ViewPager inside the Fragment is not displayed despite using getChildFragmentManager () when building the FragmentPagerAdapter

I have an internal viewpager snippet. I would like to use the FragmentPagerAdapter to scroll through fragments inside my viewpager.

public static class MyFragmentPagerAdapter extends FragmentPagerAdapter { public MyFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int index) { return new ResponderInputFragment(); } @Override public int getCount() { return 1; } 

}

I create this adapter as follows:

 viewPager = (ViewPager) v.findViewById(R.id.pager); mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager()); viewPager.setAdapter(mMyFragmentPagerAdapter); 

A ResponderInputFragment (currently my only fragment inside my viewpager) is called, such as onCreateView and onCreate, but nothing is displayed on the screen where the viewpager should be located (also there are no errors in logcat).

Layout for a FragmentActivity that contains my fragment:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#D2D9DB" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="3dip" android:background="@drawable/laser_background" /> <FrameLayout android:id="@+id/responder_fragment_container" android:layout_width="match_parent" android:layout_margin="10dip" android:layout_height="match_parent" > </FrameLayout> </LinearLayout> 

I put my fragment in a clot as follows:

 android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction(); ft.replace(R.id.responder_fragment_container, new ResponderMultipleFragment()); ft.commit(); 
+4
source share

Source: https://habr.com/ru/post/1488677/


All Articles