I use the ActionBarSherlock and ViewPagerIndicator libraries to implement the sliding effect and the action bar. As a result, I can draw different fragments, but the title of the indicator is not displayed.
Here is my fragmentmentctivity
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 is 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); } }
source share