android - strange behavior of image view selector in class which extends imageview -


i trying add simple selector object - imageview - instance of class extends imageview.

final packagetypeview ptv = packagetypeviewslist.get(index);             index++;               drawable drawable = getresources().getdrawable(                     r.drawable.selector);               imagetitleview imageview = new imagetitleview(                     getactivity());              imageview.setimagebitmap(beanutils.decodesampledbitmapfromresource(new file(ptv.gettilerenderpath()), screenwidth, screenwidth));              if (ptv.gettitlebgargb() != null) {                 imageview.setcolorcode(ptv.gettitlebgargb());             }               imageview.setimagedrawable(drawable);              //todo check entry in database             if (ptv.isshowingtitle()) {                 imageview.setdescription(ptv.getname());             }              imageview.setscaletype(scaletype.center_crop);             imageview.setclickable(true);             // imageview.setimageresource(r.drawable.selector);             imageview.setonclicklistener(this);             imageview.settag(ptv.getid()); 

and here imagetitleview class.

public class imagetitleview extends imageview {      private string description;      private string colorcode = "aaaaaabb";      private static float fontsize = -1;      private paint paint = new paint();      private rect rect = new rect();      private bitmap bitmap = null;      private static typeface tf = typeface.create("helvetica", typeface.bold);      public imagetitleview(context context, bitmap bitmap) {         super(context);         initpaint(context);         this.bitmap = bitmap;     }      public imagetitleview(context context) {         super(context);         initpaint(context);     }      public imagetitleview(context context, string description) {         super(context);         this.description = description;         initpaint(context);     }      public imagetitleview(context context, attributeset attrs) {         super(context, attrs);         initpaint(context);     }      public imagetitleview(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);         initpaint(context);     }      private void initpaint(context context) {         fontsize = context.getresources().getdimension(r.dimen.text_size_grid_info);         paint.settextsize(fontsize);         paint.settypeface(tf);     }      @override     protected void ondraw(canvas canvas) {         // todo auto-generated method stub         super.ondraw(canvas);          if (description != null) {             rect.set(new rect(0, canvas.getheight() - (canvas.getheight() / 4), canvas.getwidth(), canvas.getheight()));             paint.setcolor(color.parsecolor("#" + colorcode));             canvas.drawrect(rect, paint);              float y = rect.top + ( (rect.bottom - rect.top) / 2 + fontsize / 2);             paint.setcolor(color.white);             canvas.drawtext(description, 15, y, paint);          }     }      problem the following when add selector imageview's bitmap replaced        public string getdescription() {         return description;     }      public void setdescription(string description) {         this.description = description;     }      public string getcolorcode() {         return colorcode;     }      public void setcolorcode(string colorcode) {         if (colorcode != null && !colorcode.isempty()) {             this.colorcode = colorcode;         }     }      @override     public void setclickable(boolean clickable) {            super.setclickable(clickable);     }      @override     public void setimagebitmap(bitmap bm) {         super.setimagebitmap(bm);            } } 

and here selector:

<item android:state_pressed="true" android:drawable="@color/button_pressed_color"/> <item android:state_focused="true" android:drawable="@color/button_pressed_color"/> <item android:drawable="@android:color/transparent"/> 

the problem selector change background of imageview object , replace bitmap object transparent background.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -