Created
October 30, 2013 08:31
-
-
Save billynyh/7229002 to your computer and use it in GitHub Desktop.
#android AutoViewPager, simply take the children defined in xml as viewpager item [NOT well tested]
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
public class AutoViewPager extends ViewPager { | |
public AutoViewPager(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(); | |
} | |
public AutoViewPager(Context context) { | |
super(context); | |
init(); | |
} | |
private void init() { | |
this.setAdapter(new AutoPagerAdapter()); | |
} | |
@Override | |
public void addView(View child, int index, ViewGroup.LayoutParams params) { | |
super.addView(child, index, params); | |
this.getAdapter().notifyDataSetChanged(); | |
} | |
private class AutoPagerAdapter extends PagerAdapter { | |
public Object instantiateItem(View collection, int position) { | |
return AutoViewPager.this.getChildAt(position); | |
} | |
@Override | |
public int getCount() { | |
return AutoViewPager.this.getChildCount(); | |
} | |
@Override | |
public boolean isViewFromObject(View arg0, Object arg1) { | |
return arg0 == ((View) arg1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment