Created
June 21, 2016 19:15
-
-
Save brunodles/4e3e2bf36a3ffb5d2c5eeb8429211fbf to your computer and use it in GitHub Desktop.
Base adapter for Views inside viewpager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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