I am developing a Project in which I am using View Pager on one screen, It only has two pages.
On the first one i have a simple form with some widgets. On the second page I have listview with some products name and quantitys.
Is possible to change from the first page to second after selecting an specific option of a spinner placed in this first page (Frgament)?
I have read on similar questions that this method :
ViewPager.setCurrentItem(int index);
makes possible changing to an specific page, the thing is i don't know how to reference to this viewpager object that i declare on my activity host from my fragment.
Though, I don't understand the scenario completely. From what I understood, this is a hack that'd work in this case.
In Activity:
public ViewPager getViewPager() {
if (null == mViewPager) {
mViewPager = (ViewPager) findViewById(R.id.view_pager_id)
}
return mViewPager;
}
In Fragment:
((YourActivitName)getActivity()).getViewPager().setCurrentItem(index);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With