ViewPagerIndicator does not display title text
Asked Answered
P

1

6

I use the ActionBarSherlock and ViewPagerIndicator libs to implement the sliding effect and action bar. As a result, I can swipe the different Fragments, but the indicator title is not displayed.

Captured Screen

Here's my FragmentActivity

public class eventActivity extends SherlockFragmentActivity {
    ViewPagerFragmentAdapter mAdapter;
    ViewPager mPager;
    PageIndicator mIndicator;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.event_layout);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(true);

    mAdapter = new ViewPagerFragmentAdapter(getSupportFragmentManager());
    mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);
    mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
    mIndicator.setCurrentItem(1);

}
   ......

Here's my adapter

    public static class ViewPagerFragmentAdapter extends FragmentPagerAdapter implements TitleProvider {

    ArrayList<Fragment> fragments = new ArrayList<Fragment>();
    ArrayList<String> titles = new ArrayList<String>();

    public ViewPagerFragmentAdapter(FragmentManager fm) {
        super(fm);
        fragments.add(new eventInvitedFragment());
        titles.add("Invited");
        fragments.add(new eventAllFragment());
        titles.add("all");
        fragments.add(new eventParticipatedFragment());
        titles.add("participated");
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public String getTitle(int position) {
        return titles.get(position);
    }
}
Pteropod answered 25/5, 2012 at 1:13 Comment(0)
P
12

I have solved the problem by changing the getTitle(int position) to getPageTitle(int) in ViewPagerFragmentAdapter. ViewPagerIndicator ChangLog has the following description:

Title indicator adapter callback now uses the standard getPageTitle(int) method introduced in the r6 version of the support library.

Pteropod answered 29/5, 2012 at 8:53 Comment(3)
Thanks for posting the solution to your own question. It helped me.Astrogate
I use getPageTitle(int) method to return the title but the problem wasn't be solved. Please help me.Phylum
@NguyenMinhBinh Are you missing 'tabLayout.setupWithViewPager(mViewPager);' ? This is one of the reason you will not see tabsDoubs

© 2022 - 2024 — McMap. All rights reserved.