How to enable button at the end of viewpager in Android? -


i new in android. trying implement button in front view @ end of view pager. button stay hidden while sliding images , button visible if @ end of viewpager.. how correct?

i tried position of images , inserted if statement button visible it's not working. please me...

public class guestactivity extends activity {  viewpager viewpagerguest; mypageradapter mypageradapter;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.guestactivity);     viewpagerguest = (viewpager)findviewbyid(r.id.myviewpager);     mypageradapter = new mypageradapter();     viewpagerguest.setadapter(mypageradapter);  }  private class mypageradapter extends pageradapter {      int numberofpages = 5;      int[] res = {             r.drawable.meme1,             r.drawable.meme2,             r.drawable.meme4,             r.drawable.meme3,             r.drawable.meme5     };      int[] backgroundcolor = {             0xff101010,             0xff202020,             0xff303030,             0xff404040,             0xff505050};      @override     public int getcount() {         return numberofpages;     }      @override     public boolean isviewfromobject(view view, object object) {         return view == object;     }      @override     public object instantiateitem(viewgroup container, int position) {           textview textview = new textview(guestactivity.this);         textview.settextcolor(color.white);         textview.settextsize(30);         textview.settypeface(typeface.default_bold);         textview.settext(string.valueof(position));         textview.setgravity(view.text_alignment_center);          imageview imageview = new imageview(guestactivity.this);         imageview.setimageresource(res[position]);         viewgroup.layoutparams imageparams = new viewgroup.layoutparams(                 viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);         imageview.setlayoutparams(imageparams);          relativelayout layout = new relativelayout(guestactivity.this);         viewgroup.layoutparams layoutparams = new viewgroup.layoutparams(                 viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);         layout.setbackgroundcolor(backgroundcolor[position]);         layout.setlayoutparams(layoutparams);         layout.addview(textview);         layout.addview(imageview);          final int page = position;         if (page == 3){             button btnjoin = (button) findviewbyid(r.id.btnjoin);             btnjoin.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     intent intentjoin = new intent(guestactivity.this, loginactivity.class);                     startactivity(intentjoin);                 }             });         }         layout.setonclicklistener(new view.onclicklistener(){              @override             public void onclick(view v) {              }});          container.addview(layout);         return layout;     }      @override     public void destroyitem(viewgroup container, int position, object object) {         container.removeview((relativelayout)object);     }  }  } 

@override public int getcount() {     return numberofpages + 2; }  @override public object instantiateitem(viewgroup container, int position) {     relativelayout layout = new relativelayout(guestactivity.this);     viewgroup.layoutparams layoutparams = new viewgroup.layoutparams(     viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);     layout.setlayoutparams(layoutparams);     if (position == 0 || position == numberofpages) {         button btnjoin = (button) findviewbyid(r.id.btnjoin);             btnjoin.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     intent intentjoin = new intent(guestactivity.this, loginactivity.class);                     startactivity(intentjoin);                 }             });         layout.addview(btnjoin);     } else {         position++;         textview textview = new textview(guestactivity.this);         textview.settextcolor(color.white);         textview.settextsize(30);         textview.settypeface(typeface.default_bold);         textview.settext(string.valueof(position));         textview.setgravity(view.text_alignment_center);          imageview imageview = new imageview(guestactivity.this);         imageview.setimageresource(res[position]);         viewgroup.layoutparams imageparams = new viewgroup.layoutparams(                 viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent);         imageview.setlayoutparams(imageparams);         layout.setbackgroundcolor(backgroundcolor[position]);         layout.addview(textview);         layout.addview(imageview);          final int page = position;          layout.setonclicklistener(new view.onclicklistener(){              @override             public void onclick(view v) {              }});     }        container.addview(layout);     return layout; } 

but best use recycleview


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -