java - Checkable GridView -


hi i'm writhing checkable gridview , working. not way intending (as usual) works want except there latency when the checkbox being drawn.

the grid become true image wont draw until check grid. same goes unchecking false statement.

its easy , stupid feel ive become bit blind staring @ it. many tanks.

   public class checkableimageview extends imageview implements checkable {       private boolean mchecked=false;      public checkableimageview(final context context,             final attributeset attrs) {         super(context, attrs);     }      @override     public void toggle() {         setchecked(!mchecked);         toast.maketext(getbasecontext(), "toggle  "+mchecked,                       toast.length_short)                 .show();      }      @override     public boolean ischecked() {         toast.maketext(getbasecontext(), "checked", toast.length_short)                 .show();         return mchecked;     }      @override     public void setchecked(final boolean checked) {         if (mchecked == checked)             return;         mchecked = checked;         refreshdrawablestate();      }       @override      protected void ondraw(canvas canvas) {      super.ondraw(canvas);      if(mchecked) {      bitmap check = bitmapfactory.decoderesource(      getresources(), r.drawable.cecked);      canvas.drawbitmap(check, 0,0, new paint());       }      } 

adapter/////////////////////////////////////////////////////////////////7

             public class imageadapter extends baseadapter {     private context context;      public imageadapter(context c) {         context = c;      }      @override     public int getcount() {         // todo auto-generated method stub         // return randomlist.size();         return 12;     }      @override     public object getitem(int position) {         // todo auto-generated method stub         return position;     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {           checkableimageview imageview;         if (convertview == null) {             imageview = new checkableimageview(context, null);             imageview.setlayoutparams(new gridview.layoutparams(240, 240));             imageview.setscaletype(imageview.scaletype.center_crop);             imageview.setpadding(5, 5, 5, 5);          } else {             imageview = (checkableimageview) convertview;           }          imageview.setimageresource(randomlist.get(position));           return imageview;     }  } 

onitemclick/////////////////////////////////////////////

            @override         public void onitemclick(adapterview parent, view v, int position,                 long id) {                 cv = (checkableimageview) v;               cv.toggle();               cv.refreshdrawablestate();          }     }); 

you need call:

notifydatasetchanged(); 

on adapter when change data or information pertaining it. cause grid become invalidated , redraw based on have overridden in getview() method of adapter.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -