java - Change Tablayout image from Viewpager Swipe -
/* hello read im trying simple. im creating slide show. have view pager tablayout. tablayout going used indicator viewpager. problem setting background drawable selected tab within view pager. tried tab layout position , set background drawable thats not working well. posted code if need anymore information let me know. */
public class tutoralactivity extends appcompatactivity { private viewpager viewpager; private pageradapter pageradapter; private tablayout tablayout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tutoral); int images[] = { r.drawable.t1, r.drawable.t2, r.drawable.t3, r.drawable.t4 }; viewpager = (viewpager) findviewbyid(r.id.imageviewpager); tablayout = (tablayout) findviewbyid(r.id.tutorial_dot_indicator); mycustomadapter customadapter = new mycustomadapter(tutoralactivity.this, images); viewpager.setadapter(customadapter); viewpager.addonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { } @override public void onpageselected(int position) { tablayout.gettabat(position).seticon(mydrawableimage); } @override public void onpagescrollstatechanged(int state) { } }); tablayout.setupwithviewpager(viewpager); } private class mycustomadapter extends pageradapter { context context; int images[]; layoutinflater layoutinflater; public mycustomadapter(context context, int[] images) { this.context = context; this.images = images; layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public void destroyitem(viewgroup container, int position, object object) { // super.destroyitem(container, position, object); container.removeview((view) object); } @override public object instantiateitem(viewgroup container, int position) { view imageviewlayout = layoutinflater.inflate(r.layout.tutorial_layout, container, false); imageview imagetoshow = (imageview) imageviewlayout.findviewbyid(r.id.tutorial_image); imagetoshow.setimageresource(images[position]); button btndone = (button) imageviewlayout.findviewbyid(r.id.btnimagedone); btndone.setvisibility(view.invisible); container.addview(imageviewlayout); return imageviewlayout; } @override public int getcount() { return images.length; } @override public boolean isviewfromobject(view view, object object) { return view == ((linearlayout) object); } } }
wiki
Comments
Post a Comment