Skip to content

Instantly share code, notes, and snippets.

@manishkpr
Created December 30, 2016 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manishkpr/815e85e07572641a8e66a6894c84d98f to your computer and use it in GitHub Desktop.
Save manishkpr/815e85e07572641a8e66a6894c84d98f to your computer and use it in GitHub Desktop.
public class TabsPagerAdapter extends PagerAdapter {
String tabs[]={"Test 1","Test 2","Test 3","Test 4","Test 5","Test 6","Test 7","Test 8"};
Activity activity;
public TabsPagerAdapter(Activity activity){
this.activity=activity;
}
@Override
public int getCount() {
return tabs.length;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return o == view;
}
@Override
public CharSequence getPageTitle(int position) {
return tabs[position];
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// Inflate a new layout from our resources
View view=null;
if(position%2==0){
view = activity.getLayoutInflater().inflate(R.layout.pager_item,container, false);
}else{
view = activity.getLayoutInflater().inflate(R.layout.pager_item_2,container, false);
}
// Add the newly created View to the ViewPager
container.addView(view);
// Retrieve a TextView from the inflated View, and update it's text
TextView title = (TextView) view.findViewById(R.id.item_title);
title.setText(tabs[position]);
// Return the View
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment