public class

ViewPager

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.ViewPager

Class Overview

A ViewPager control allows the user to flip left and right through pages of data.

Either you supply an implementation of a PagerAdapter (with setPagerAdapter()) to generate the pages that the view shows or you provide views with addView() for each pages.

Summary

[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
ViewPager()
Creates a new view pager.
Public Methods
void addView(View view, int atIndex)
Inserts a view (as a page) at a specified position.
void addView(View view)
Adds a new item view (as a page) to the ViewPager.
int getCurrentPage()
Returns the current selected tab.
int getViewsCount()
Returns the number of views (or pages) inside this container.
boolean isEnabled()
Returns a boolean indicating if the ViewPager is enabled or not.
void notifyDataChanged()
Notifies the pager that data has changed and the pager should update the UI
void removeAllViews()
Removes all views from this container.
void removeIndex(int index)
Removes a view from this list at the specified index.
void removeView(View view)
Removes a view from this list.
void setCurrentPage(int number)
Changes the current selected page.
void setEnabled(boolean enabled)
Enables or disables the ViewPager.
void setOffScreenPageLimit(int pageLimit)
Sets the number of pages that should be buffered to either side of the current page.
void setPageChangeListener(PageChangeListener listener)
Sets a page change listener to listen when the user changes the current page.
void setPagerAdapter(PagerAdapter adapter)
Set a PagerAdapter that will supply views for this pager as needed.
void setPagerTitleStrip(PagerTitleStrip titleStrip)
Sets a PagerTitleStrip to this ViewPager.
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

Public Constructors

public ViewPager ()

Creates a new view pager.

Public Methods

public void addView (View view, int atIndex)

Inserts a view (as a page) at a specified position.

Parameters
view the view to insert
atIndex the position index

public void addView (View view)

Adds a new item view (as a page) to the ViewPager.

Parameters
view child to add
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalStateException if the view child has already a parent

public int getCurrentPage ()

Returns the current selected tab.

Returns
  • the integer value of the selected tab

public int getViewsCount ()

Returns the number of views (or pages) inside this container.

Returns
  • the number of views

public boolean isEnabled ()

Returns a boolean indicating if the ViewPager is enabled or not. When the pager is disabled, it cannot be scrolled.

Returns
  • true if the ViewPager is enabled, false if it is disabled

public void notifyDataChanged ()

Notifies the pager that data has changed and the pager should update the UI

public void removeAllViews ()

Removes all views from this container.

Throws
CrossThreadException if the method is called from outside the UI-Thread

public void removeIndex (int index)

Removes a view from this list at the specified index.

public void removeView (View view)

Removes a view from this list. if the view is not a child of this ListView, an IllegalStateException is thrown.

Parameters
view the view to remove
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalStateException if the view is not a child of this list
NullPointerException if the view is null

public void setCurrentPage (int number)

Changes the current selected page. If the index of the page is outside the pager bounds, nothing is done.

Parameters
number current tab index
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setEnabled (boolean enabled)

Enables or disables the ViewPager. When the pager is disabled, it cannot be scrolled.

Parameters
enabled the new state of the ViewPager: true for enabled, false for disabled
Throws
CrossThreadException if the method is called from outside the UI-Thread
See Also

public void setOffScreenPageLimit (int pageLimit)

Sets the number of pages that should be buffered to either side of the current page. Pages beyond this limit will be recreated from the adapter when needed.

By default, the limit is set to 1. This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth. You should keep this limit low, especially if your pages have complex layouts.

Parameters
pageLimit the number of pages that should be buffered to either side of the current page

public void setPageChangeListener (PageChangeListener listener)

Sets a page change listener to listen when the user changes the current page.

Parameters
listener a listener or null

public void setPagerAdapter (PagerAdapter adapter)

Set a PagerAdapter that will supply views for this pager as needed.

Parameters
adapter Adapter to use
See Also

public void setPagerTitleStrip (PagerTitleStrip titleStrip)

Sets a PagerTitleStrip to this ViewPager. This will enable to display titles for each pages of the pager. Titles will be displayed above the pager and will move with their associated page.

Parameters
titleStrip the PagerTitleStrip that will contain the titles of the pager pages