Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 337
Waza_Be Avatar asked Mar 10 '13 10:03

Waza_Be


1 Answers

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.

like image 118
nikib3ro Avatar answered Sep 27 '22 21:09

nikib3ro