Dynamically change the title of a android.support.v4.view.PagerTitleStrip

Waza_Be picture Waza_Be · Mar 10, 2013 · Viewed 9.6k times · Source

I am currentky using a PagerTitleStrip in my application (Doc: http://developer.android.com/reference/android/support/v4/view/PagerTitleStrip.html)

Everything works fine, and I have set the title like this:

public class PageAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;

    public PageAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

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

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

    String[] titles = { "1", "2", "3", "4","5" };

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}

My concern now, is that once the first Fragment has finished loading, I have to change the title of the strip.

I have already tried to get the FragmentPagerAdapter and tried to manipulate it, but never succeed to change a title (text)

There is indeed a getPageTitle method: mPagerAdapter.getPageTitle(position) but no setPageTitle ...

Any idea or suggestion?

Answer

nikib3ro picture nikib3ro · Mar 10, 2013

If I understand problem correctly - you get data later and then want to update titles array and trigger refresh of titles.

If that's the case just trigger PagerAdapter.notifyDataSetChanged(); after that method is invoked Fragments will call getPageTitle method and update themselves.