androidfragmentpageradapter

tabs with date as title


I need tab layouts with the titles as dates in it. In my pager adapter I'm using the following code.

private static final int[] TAB_TITLES = new int[]{R.string.home_tab1, R.string.home_tab2, R.string.home_tab3};

It is working correctly. How can I pass a date with weekdays in integer acceptable parameters. Help me


Solution

  • U can pass an array of string to your CustomPagerAdapter and override getPageTitle inside ur adapter.

    public class CustomPagerAdapter extends PagerAdapter {
    
    private List<String> titleArray;
    
    public CustomPagerAdapter(List<String> titleArray) {
        this.titleAray = titleArray;
    
    @Override
    public CharSequence getPageTitle(int position) {
        return titleArray.get(position);
      }
    }