I am creating ViewPager
and want to call the next Pager
on Button.OnClickListener
. Setting adapter from the following code in Activity
:
@EActivity(R.layout.activity_city)
public class CountrySelectionActivity extends Activity {
@ViewById ViewPager viewPager;
@Bean CustomAdapter customAdapter;
@AfterViews
void afterViewCreated(){
viewPager.setAdapter(customAdapter);
}
}
Here is the code for CustomAdapter
class:
@EBean
public class CustomAdapter extends PagerAdapter {
public CustomAdapter(Context context) {
mContext = context;
loadData(); // loading data as in List
}
......
......
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
TextView firstCountry;
TextView secondCountry;
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
View view = layoutInflater.inflate(R.layout.country_pager_item, container, false);
....
....
}
Everything is working fine. I can see the ViewPager
loading the two countries on every pages
.
I can also slide the pages
(Previous and Next). But I want to move to next Pager as soon as click on TextView
and so on. Is it possible to do it in ViewPager
?