Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I based this on the samples that come with the <code>ViewPagerIndicator</code>.</p> <p>You basically listen for when the page changes and tell the adapter to display a different page title depending on the current position.</p> <p>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...</p> <p>Changed the code for <code>TestFragmentAdapter</code> like this:</p> <pre><code>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 &gt; 0 &amp;&amp; count &lt;= 10) { mCount = count; notifyDataSetChanged(); } } } </code></pre> <p>the code for <code>SampleTitlesDefault</code> looks like this (added the OnPageChangeListener)</p> <pre><code>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 } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload