Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

@Override
    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.

like image 524
Roman Avatar asked Apr 30 '15 15:04

Roman


1 Answers

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

private OrdersTabsAdapter tabsAdapter;
@InjectView(R.id.tabs_orders) SlidingTabLayout ordersTabs;
@InjectView(R.id.pager) ViewPager pager;

public void update() {
  tabsAdapter.updateFragments(productId, status);
  ordersTabs.setViewPager(pager); //this helped with the titles
}
like image 192
Roman Avatar answered Oct 06 '22 17:10

Roman