ViewPagerIndicator does not display title text

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.

Captured screen

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); } } 
+6
source share
1 answer

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

The header header adapter callback now uses the standard getPageTitle (int) method introduced in the r6 support library version.

+12
source

Source: https://habr.com/ru/post/916614/


All Articles