Roman Roman - 1 year ago 133
Android Question

FragmentPagerAdapter update title dynamically

I have a ViewPager with FragmentPagerAdapter, which has 3 Fragments. Now, I have a number of items as part of the title of the fragment:

enter image description here

So user can add or remove those items, and title should update accordingly. However, this title seems static.

How can one recall this method to update FragmentPagerAdapter's titles?

public CharSequence getPageTitle(int position) {
switch (position) {
case 0: return items + " (" + notFoundItems + ")";
case 1: return found;
case 2: return review;
return "";

I found a couple of similar questions on SO, but I need to update title, not only the fragment itself.

Answer Source

Finally, I solved it by simply re-setting the pager.

private OrdersTabsAdapter tabsAdapter;
@InjectView( SlidingTabLayout ordersTabs;
@InjectView( ViewPager pager;

public void update() {
  tabsAdapter.updateFragments(productId, status);
  ordersTabs.setViewPager(pager); //this helped with the titles
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download