android - ViewPager behaves in an unexpected way -
my goal implement guide/how-to-use-app activity in app, users can flip between predefined set of views. so, decided use viewpager.
this how did in guideactivity
:
mpager = (viewpager) findviewbyid(r.id.pager); madapter = new guideadapter(getbasecontext()); mpager.setadapter(madapter);
and implementation of pageradapter
:
class guideadapter extends pageradapter { private context context; protected static final int[] slides = new int[] { r.drawable.page1, r.drawable.page2, r.drawable.page3 }; public guideadapter(context context) { this.context = context; } @override public view instantiateitem(viewgroup container, int position) { imageview image = new imageview(container.getcontext()); image.setimageresource(slides[position]); container.addview(image, layoutparams.wrap_content, layoutparams.wrap_content); return image; } @override public void destroyitem(viewgroup collection, int position, object view) { ((viewpager) collection).removeview((view) view); } @override public int getcount() { return slides.length; } @override public boolean isviewfromobject(view arg0, object arg1) { return true; } }
the problem is, images drawn in top of each other. if scroll left right, see no images. if scroll back, images shown second disappear. bottom line: viewpager behave in unexpected way!
i overridden four required methods in pageradapter
. i'm not sure did wrong think has instantiateitem()
and/or destroyitem()
.
any ideas?
this needed:
@override public boolean isviewfromobject(view view, object object) { return view == object; }
Comments
Post a Comment