Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPagerIndicator does not display title text

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);
    }
}
like image 601
yee Avatar asked May 25 '12 01:05

yee


1 Answers

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.

like image 169
yee Avatar answered Nov 17 '22 21:11

yee