android - How do I dim an imageview from an ImageAdapter Grid View class? -


i trying create logo quiz, works, unable figure out how modify specific image imageadapter. guidance highly appreciated. thank you!

here quiz activity:

public class quizactivity extends activity { private interstitialad interstitial; private static int size = 50; public static int location; private int counter = 0;  // initialize buttons public static imagebutton buttons[] = new imagebutton[size];  // array names public static string[] names = { "hannibal", "orphan black", "lord of rings",         "pretty little liars", "harry potter", "star trek",         "the fault in our stars", "iron man", "thor", "frozen",         "harry potter", "game of thrones", "hannibal", "doctor who",         "sherlock", "attack on titan", "teen wolf", "game of thrones",         "doctor who", "sherlock", "supernatural", "the hunger games",         "american horror story", "breaking bad", "attack on titan",         "teen wolf", "doctor who", "sherlock", "supernatural", "sherlock",         "arrow", "the big bang theory", "mad men", "arrested development",          "game of thrones", "breaking bad", "sons of anarchy", "the graduate",         "et", "scooby doo", "wizard of oz", "linux", "simpsons", "iron man", "wonder woman",         "green lantern", "flash", "captain america", "thor", "the picture of dorian gray"   };  // array images public int[] images = { r.drawable.image1, r.drawable.image2,         r.drawable.image3, r.drawable.image4, r.drawable.image5,         r.drawable.image6, r.drawable.image7, r.drawable.image8,         r.drawable.image9, r.drawable.image10, r.drawable.image11,         r.drawable.image12, r.drawable.image13, r.drawable.image14,         r.drawable.image15, r.drawable.image16, r.drawable.image17,         r.drawable.image18, r.drawable.image19, r.drawable.image20,         r.drawable.image21, r.drawable.image22, r.drawable.image23,         r.drawable.image24, r.drawable.image25, r.drawable.image26,         r.drawable.image27, r.drawable.image28, r.drawable.image29,         r.drawable.image30,         r.drawable.image31, r.drawable.image32, r.drawable.image33,         r.drawable.image34, r.drawable.image35, r.drawable.image36,         r.drawable.image37, r.drawable.image38, r.drawable.image39,         r.drawable.image40,         r.drawable.image41, r.drawable.image42, r.drawable.image43,         r.drawable.image44, r.drawable.image45, r.drawable.image46,         r.drawable.image47, r.drawable.image48, r.drawable.image49,         r.drawable.image50};  gridview gridview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      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) {             //toast.maketext(quizactivity.this, "" + position, toast.length_short).show();             // popupactivity             intent intent = new intent(quizactivity.this, popupwindow.class);             intent.putextra("position", position);             intent.putextra("images", images);             intent.putextra("names", names);              startactivity(intent);             counter++;             if (counter == 2) {                 counter = 0;                 // ad                 displayinterstitial();             }         }     });  }  // invoke displayinterstitial() when ready display // interstitial. public void displayinterstitial() {      // create ad request.     adrequest adrequest = new adrequest.builder().build();      // begin loading interstitial.     interstitial.loadad(adrequest);      if (interstitial.isloaded()) {         interstitial.show();     } }  public void dimimage(){    //item..setalpha(300); <- confused  }  } 

and imageadapter class:

public class imageadapter extends baseadapter { private context mcontext;  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) {  // if it's not recycled, initialize attributes         imageview = new imageview(mcontext);         imageview.setlayoutparams(new gridview.layoutparams(85, 85));         imageview.setscaletype(imageview.scaletype.center_crop);         imageview.setpadding(8, 8, 8, 8);     } else {         imageview = (imageview) convertview;     }      imageview.setimageresource(mthumbids[position]);      return imageview; }  // references our images public integer[] mthumbids = {         r.drawable.image1, r.drawable.image2,         r.drawable.image3, r.drawable.image4,         r.drawable.image5, r.drawable.image6,         r.drawable.image7, r.drawable.image8,         r.drawable.image9, r.drawable.image10,         r.drawable.image11, r.drawable.image12,         r.drawable.image13, r.drawable.image14,         r.drawable.image15, r.drawable.image16,         r.drawable.image17, r.drawable.image18,         r.drawable.image19, r.drawable.image20,         r.drawable.image21, r.drawable.image22 }; 

yes, random correct. can have adapter keep track of items have been dimmed, , check setting of particular item in getview:

public class imageadapter extends baseadapter {     private context mcontext;     private int msize;     private boolean [] mdim;      public imageadapter(context c, int size) {         mcontext = c;         msize = size;         mdim = new boolean[size];     }      public void dimimage(int position) {         mdim[position] = true;     }      // create new imageview each item referenced adapter     public view getview(int position, view convertview, viewgroup parent) {         imageview imageview;         if (convertview == null) {  // if it's not recycled, initialize attributes             imageview = new imageview(mcontext);             imageview.setlayoutparams(new gridview.layoutparams(85, 85));             imageview.setscaletype(imageview.scaletype.center_crop);             imageview.setpadding(8, 8, 8, 8);         } else {             imageview = (imageview) convertview;         }          imageview.setimageresource(mthumbids[position]);         imageview.setalpha(mdim[position] ? 0.5f : 1.0f);          return imageview;     } } 

in activity, keep adapter in field, construct adapter size, , when want dim image, call adapter.dimimage(position), followed notifydatasetchanged:

public class quizactivity extends activity {     private imageadapter adapter;     private gridview gridview;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          adapter = new imageadapter(this, size);         gridview = (gridview) findviewbyid(r.id.gridview);         gridview.setadapter(adapter);         ...     }      public void dimimage(){         adapter.dimimage(location); // not sure if location represents image index         adapter.notifydatasetchanged();     } 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -