Skip to content

Instantly share code, notes, and snippets.

@brunodles
Created June 21, 2016 19:15
Show Gist options
  • Save brunodles/4e3e2bf36a3ffb5d2c5eeb8429211fbf to your computer and use it in GitHub Desktop.
Save brunodles/4e3e2bf36a3ffb5d2c5eeb8429211fbf to your computer and use it in GitHub Desktop.
Base adapter for Views inside viewpager
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
public abstract class ViewPagerAdapter extends PagerAdapter {
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = getItem(container, position);
container.addView(view);
return view;
}
protected abstract View getItem(ViewGroup container, int position);
@Override
public final void destroyItem(ViewGroup container, int position, Object object) {
View view = (View) object;
container.removeView(view);
}
@Override
public final boolean isViewFromObject(View view, Object object) {
return (view == object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment