Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:29+00:00 2026-06-15T16:38:29+00:00

I have a ViewPager in which I am using the getPageTitle method to get

  • 0

I have a ViewPager in which I am using the getPageTitle method to get the title of the current page.

Here is the Adapter code:

    @Override
    public Fragment getItem(int i) {
        details = productData.get(i);
        Fragment fragment = new ProductViewFragment();
        Bundle args = new Bundle();
        args.putInt(ProductViewFragment.ARG_SECTION_NUMBER, i + 1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getCount() {
        return productData.size();
    }

    public CharSequence getPageTitle(int position) 
    {
      return (position+1)+" of "+myData.size();
    }

Now I would like to update the page titles of the previous and next fragments. I want to name them as “previous” and “next”. And it should be updated dynamically on subsequent pages also.

I am able to get the current page title number. For example, when I view the 5th fragment, the current fragment will show the title properly. And at both the corners of the ViewPager it shows the previous page title number on the left and next page title number on the right. Now, I want to have the page titles as “previous” on the left and “next” on the right, similar to the Gmail app and how it shows the mail count in the ViewPager.

The main thing I want to know is how can I access/modify the page title data of the next/previous fragments from the current fragment like they do in the Gmail app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:38:30+00:00Added an answer on June 15, 2026 at 4:38 pm

    I based this on the samples that come with the ViewPagerIndicator.

    You basically listen for when the page changes and tell the adapter to display a different page title depending on the current position.

    If you have those samples working and you just replace those two files, then try the sample Titles->Default and it works fine for me…

    Changed the code for TestFragmentAdapter like this:

    package com.viewpagerindicator.sample;
    
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import com.viewpagerindicator.IconPagerAdapter;
    
    class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
        protected static final String[] CONTENT = new String[] { "This", "Is", "A", "Test", };
        protected static final int[] ICONS = new int[] {
                R.drawable.perm_group_calendar,
                R.drawable.perm_group_camera,
                R.drawable.perm_group_device_alarms,
                R.drawable.perm_group_location
        };
    
        private int mCount = CONTENT.length;
    
        // CHANGE STARTS HERE
        private int current_position=0;
    
        public void set_current_position(int i) {
            current_position = i;
        }
        // CHANGE ENDS HERE
    
        public TestFragmentAdapter(FragmentManager fm) {
            super(fm);
        }
    
        @Override
        public Fragment getItem(int position) {
            return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
        }
    
        @Override
        public int getCount() {
            return mCount;
        }
    
        @Override
        public CharSequence getPageTitle(int position) {
            // CHANGE STARTS HERE
            if (position == current_position-1) {
                return "Previous";
            } else if (position == current_position+1) {
                return "Next";
            }
            // CHANGE ENDS HERE
            return TestFragmentAdapter.CONTENT[position % CONTENT.length];
        }
    
        @Override
        public int getIconResId(int index) {
          return ICONS[index % ICONS.length];
        }
    
        public void setCount(int count) {
            if (count > 0 && count <= 10) {
                mCount = count;
                notifyDataSetChanged();
            }
        }
    }
    

    the code for SampleTitlesDefault looks like this (added the OnPageChangeListener)

    package com.viewpagerindicator.sample;
    
    import android.os.Bundle;
    import android.support.v4.view.ViewPager;
    
    import com.viewpagerindicator.TitlePageIndicator;
    
    // CHANGE ADDED implements.... HERE
    public class SampleTitlesDefault extends BaseSampleActivity implements ViewPager.OnPageChangeListener {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_titles);
    
            mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    
            mPager = (ViewPager)findViewById(R.id.pager);
            mPager.setAdapter(mAdapter);
    
            mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
            mIndicator.setViewPager(mPager);
            // CHANGE STARTS HERE
            mIndicator.setOnPageChangeListener(this);
            // CHANGE ENDS HERE
        }
    
        // CHANGE STARTS HERE
        @Override
        public void onPageScrolled(int i, float v, int i1) {
        }
    
        @Override
        public void onPageSelected(int i) {
            mPager = (ViewPager)findViewById(R.id.pager);
            ((TestFragmentAdapter)mPager.getAdapter()).set_current_position(i);
        }
    
        @Override
        public void onPageScrollStateChanged(int i) {
        }
        // CHANGE ENDS HERE
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project using a ViewPager which works correctly: I can page from
I have a main page which looks like: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage
I have this loop method to display a ViewPager and I set an OnClickListener
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
I have a view that is strongly typed: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage<MPKwithMVC.Models.SmartFormViewModel>
I am trying to create fragments inside viewpager. In the adapter I am using
I have a viewpager which has two views in it. On the first view
I am developing application using viewpager with fragment.In my application i have a items
I have a view pager which contains a fragment. When the fragment pager adapter
So it appears that when using a ViewPager, the onPageSelected listener does not get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.