Search code examples
androidandroid-viewpager

How can I set the titles in a PagerTitleStrip for a View pager


I have problem setting the title view pager by using PagerTitleStrip. I added a child view of PagerTitleStrip in view pager.

Where can I provide the title strings to apply to each page?

How can I set the page title in the Page Adapter class?


Solution

  • Override the getPageTitle method and supply your static array of pages string to it.

    String [] titlesArray = 
        new String []{ 
            page1, 
            page2,
            page3
        };
    
    public CharSequence getPageTitle(int position) {
        return titlesArray [position];
    }