ogaclejapan / SmartTabLayout

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
Apache License 2.0
7.09k stars 1.34k forks source link

Problems with tabs in fragment #124

Closed burnix closed 8 years ago

burnix commented 8 years ago

I have a navigation drawer, that has few items(that replace previous fragment). My MainActivity creates a fragment that has Sliding Tabs at start. I implement them this way:

  @Override
   public void onAttach(Activity activity) {
      myContext = (FragmentActivity) activity;
      super.onAttach(activity);
    }

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_blank, container, false);
    FragmentManager fragManager = myContext.getSupportFragmentManager();
    adapter = new FragmentPagerItemAdapter(
            fragManager, FragmentPagerItems.with(getActivity())
            .add("Каталог", Catalog.class)
            .add("Проекты", Projects.class)
            .create());

    ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);
    viewPager.setAdapter(adapter);

    SmartTabLayout viewPagerTab = (SmartTabLayout) view.findViewById(R.id.viewpagertab);
    viewPagerTab.setViewPager(viewPager);
    return view;
}

So after start in works super, but after working with items of Navigation Drawer, SlidingTabBar shows nothing, swipes becomes "flowing"...

I suppose, that my problem appears because of using v4, instead of v13. So I wanna ask you to share a piece of code, where you implement SlidingTabBar in fragment (author gives example of v.4).

ogaclejapan commented 8 years ago

Hi, @burnix

FragmentManager fragManager = myContext.getSupportFragmentManager();

Please try using the Fragment#getChildFragmentManager http://developer.android.com/intl/ja/reference/android/support/v4/app/Fragment.html#getChildFragmentManager()

If you want to use the ViewPager within Fragment, you will need to use this class.

burnix commented 8 years ago

I tried to use getChildFragmentActivity, but still can't implement SlidingTabs using v.4 library 2016-01-24 23 17 45

and using v.13 2016-01-24 23 13 12

Please, tell what Do I do wrong?

Also, while importing v13, there're no FragmentPageAdapter and FragmentStatePagerAdapter Classes 2016-01-24 23 29 16

ogaclejapan commented 8 years ago

Hi, @burnix

Utility has two types available to suit the Android support library.

・utils-v4 library contains the PagerAdapter implementation class for android.support.v4.app.Fragment ・utils-v13 library contains the PagerAdapter implementation class for android.app.Fragment

The two libraries have different Android support libraries that depend, but implemented functionality is the same.

So, if you want to use the android.support.v4.app.Fragment, please use the compile 'com.ogaclejapan.smarttablayout:utils-v4:x.x.x@aar'

burnix commented 8 years ago

I actually do it, but it still doesn't solve my problem - I can't use getChildFragmentManager(look the 2nd screen of previous answer)

ogaclejapan commented 8 years ago

Hi, @burnix

Why are you inherit the android.app.Fragment ? If you want to use the v4, you need to inherit from android.support.v4.app.Fragment.

AnasAlsaadi commented 6 years ago

i inherit from android.app.Fragment and i cant inherit from android.support.v4.app.Fragment what is the solution ?