Show different image on same Gridview Android -


i want show different image in grid layout mainactivity.java

    b1.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     if(isreadstorageallowed()){                         intent intent = new intent(mainactivity.this, gridactivity.class); intent.putextra("firstkeyname","firstkeyvalue"); intent.putextra("secondkeyname","secondkeyvalue");                         mainactivity.this.startactivity(intent);                  }             }); 

i want show images in gridlayout gridactivity.java code follows

intent intent; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); intent = getintent(); // view new_activity.xml setcontentview(r.layout.activity_grid);   gridview gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new imageadapter(this));  gridview.setonitemclicklistener(new adapterview.onitemclicklistener() {     public void onitemclick(adapterview<?> parent,                             view v, int position, long id){     } }); 

and in imageadapter want intend value of mainactivity use in filter in images(different image on single view using different button)

imageadapter.java

public class imageadapter extends baseadapter {     private context mcontext;      // constructor     public imageadapter(context c) {         mcontext = c;     }      public int getcount() {         return mthumbids.length;     }      public object getitem(int position) {         return null;     }      public long getitemid(int position) {         return 0;     }      // create new imageview each item referenced adapter     public view getview(int position, view convertview, viewgroup parent) {         imageview imageview;          /*if (convertview == null) {*/         imageview = new imageview(mcontext);         imageview.setlayoutparams(new gridview.layoutparams(350, 350));         imageview.setscaletype(imageview.scaletype.fit_start);         imageview.setpadding(8, 8, 8, 8);         /*}         else         {             imageview = (imageview) convertview;         }*/         imageview.setimageresource(mthumbids[position]);         return imageview;     }      // keep images in array     public integer[] mthumbids = {             r.drawable.b1, r.drawable.b2, r.drawable.b3,             r.drawable.b4, r.drawable.b5, r.drawable.b6,             r.drawable.b7, r.drawable.b8, r.drawable.b9,             r.drawable.b10, r.drawable.b11, r.drawable.b12,     }; 

public class imageadapter extends baseadapter {     private context mcontext;      // constructor     public imageadapter(context c) {         mcontext = c;     }      public int getcount() {         return mthumbids.length;     }      @override     public object getitem(int i) {         return mthumbids[i];     }      @override     public long getitemid(int i) {         return mthumbids[i];     }       @override     public view getview(int position, view convertview, viewgroup parent) {         imageview imageview;      /*if (convertview == null) {*/         imageview = new imageview(mcontext);         imageview.setlayoutparams(new gridview.layoutparams(350, 350));         imageview.setscaletype(imageview.scaletype.fit_start);         imageview.setpadding(8, 8, 8, 8);     /*}     else     {         imageview = (imageview) convertview;     }*/         imageview.setimageresource(mthumbids[position]);         return imageview;     }      // keep images in array     public integer[] mthumbids = {             r.drawable.b1, r.drawable.b2, r.drawable.b3,             r.drawable.b4, r.drawable.b5, r.drawable.b6,             r.drawable.b7, r.drawable.b8, r.drawable.b9,             r.drawable.b10, r.drawable.b11, r.drawable.b12,     }; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -