jpardogo / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
2.19k stars 353 forks source link

Multiple tabs issue #60

Closed taimur97 closed 9 years ago

taimur97 commented 9 years ago

I am having multiple tab layers. I don't know why this is happening.

This is how it looks screenshot from 2015-01-25 22 35 45 screenshot from 2015-01-25 22 36 13

This is my code i am using My Home Class public class HomeClass extends Fragment {

private static final String ARG_POSITION = "position";

public static HomeClass newInstance(int position) {
    HomeClass f = new HomeClass();
    Bundle b = new Bundle();
    b.putInt(ARG_POSITION, position);
    f.setArguments(b);
    return f;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    // Initialize the ViewPager and set an adapter
    ViewPager pager = (ViewPager) view.findViewById(R.id.pager);

    pager.setAdapter(new PagerAdapter(getActivity().getSupportFragmentManager()));

    // Bind the tabs to the ViewPager
    PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
    tabs.setViewPager(pager);

    return view;
}

}

My PagerAdapter Class public class PagerAdapter extends FragmentPagerAdapter { private final String[] TITLES = {"TAB1", "TAB2", "TAB3"};

public PagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    return HomeClass.newInstance(position);
}

@Override
public CharSequence getPageTitle(int position) {
    return TITLES[position];
}

@Override
public int getCount() {
    return TITLES.length;
}

}

My Layout XML file

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
   <com.astuetz.PagerSlidingTabStrip
      android:id="@+id/tabs"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      android:fillViewport="false" />
   <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
       android:layout_below="@+id/tabs" />
  </RelativeLayout>
jpardogo commented 9 years ago

Are you 100% sure that you aren't inflating a layout with two PagerSlidingTabStrip views define? or you are not adding a second one in run time? Why are you using android:fillViewport="false"?

taimur97 commented 9 years ago

okay the problem is now solved. The problem was in my adapter class