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.
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);
}
}