androidandroid-viewpagerpagerslidingtabstrip

how to make the titles in pagerSlidingTabstrip dynamic?


I need to change the titles in the pager according to the items that are dynamically changing in the child fragments in the pager. I have tried it this way

     TextView title = (TextView) mPagerSlidingTabStrip.getChildAt(1);
        title.setText("Posts " + count);

But it doesnt seem to be working. Thanks in advance


Solution

  • you can use this to access textview of each tab

        LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
        for (int i = 0; i < mTabsLinearLayout.getChildCount(); i++)
        {
            TextView tv = (TextView) mTabsLinearLayout.getChildAt(i);
            tv.setText("title");
        }
    

    Now you want perticular tab's textview so

    LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
    TextView tv = (TextView) mTabsLinearLayout.getChildAt(<perticular tab position>);
    tv.setText(yourText);