I have extended the ViewPager class and implemented onPageChangeListener. I use this ViewPager in conjunction with a CirclePageIndicator inside a SherlockFragment. The ViewPager contains ImageViews and TextViews, nothing fancy.
I need to do something below the ViewPager every time the Page is being changed. So, I figured I need to use the onPageScrollStateChanged and verify when the state is IDLE, or something.
The problem is that from the 3 implemented methods (onPageScrollStateChanged, onPageSelected and onPageScrolled), only onPageScrolled gets called (I checked with a log message in each method). Why is that ? Code below.
public class UninterceptableViewPager extends ViewPager implements OnPageChangeListener{
private ArrayList<TwoRowListViewAdapter> mAdaptersList = null;
private ListView mListView = null;
private ProgressBar mProgressBar = null;
public UninterceptableViewPager(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public boolean onInterceptTouchEvent(MotionEvent event)
{
getParent().requestDisallowInterceptTouchEvent(true);
return super.onInterceptTouchEvent(event);
}
public void setAdaptersList(ArrayList<TwoRowListViewAdapter> adaptersList)
{
mAdaptersList = adaptersList;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
super.onPageScrolled(position++, positionOffset, positionOffsetPixels);
if (positionOffset == 0) // FIXME
loadHistoryPage(position);
}
@Override
public void onPageSelected(int position) {}
@Override
public void onPageScrollStateChanged(int state) {}
// -------------------------------------------------------------------------------------------
// -------------- Helper Methods
// -------------------------------------------------------------------------------------------
public void setListView(ListView listview)
{
mListView = listview;
}
public void setProgressBar(ProgressBar progressBar)
{
mProgressBar = progressBar;
}
private void loadHistoryPage(int position)
{
mListView.setVisibility(View.INVISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
mListView.setAdapter(null);
mListView.setAdapter(mAdaptersList.get(position-1));
mProgressBar.setVisibility(View.INVISIBLE);
mListView.setVisibility(View.VISIBLE);
}
}