java - Cannot draw a circle with loading of the fragment -


i trying draw circles in canvas. can on button click, need same when fragment loaded. below fragment code.

public class steptwentyonefragment extends fragment {      private canvasview customcanvas;      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.step21_fragment, container, false);         customcanvas=(canvasview)v.findviewbyid(r.id.signature_canvas);          final button button1=(button)v.findviewbyid(r.id.step18button1);          float radius=(customcanvas.getcanvaswidth()/2) - ((customcanvas.getcanvaswidth()/2)/100)*60;         customcanvas.drawcircle(radius);          button1.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  if(v.getid()==r.id.step18button1){                      float radius=(customcanvas.getcanvaswidth()/2) - ((customcanvas.getcanvaswidth()/2)/100)*60;                     customcanvas.drawcircle(radius);                     log.d("an_width", "" + customcanvas.getcanvaswidth());                     log.d("an_height" ,""+ customcanvas.getcanvasheight());                      v.setbackgroundresource(r.drawable.button_border_5);                     button1.settextcolor(color.white);;                 }             }         });              return v;     }      public static steptwentyonefragment newinstance() {          steptwentyonefragment f = new steptwentyonefragment();         bundle b = new bundle();          f.setarguments(b);          return f;     }       @override     public void setuservisiblehint(boolean isvisibletouser) {         super.setuservisiblehint(isvisibletouser);         if(isvisibletouser) {             activity = getactivity();             if(a != null) a.setrequestedorientation(activityinfo.screen_orientation_portrait);         }     }      } 

below canvas code

public class canvasview extends view {      public int width;     public int height;     private bitmap mbitmap;     private canvas mcanvas;     private path mpath;     context context;     private paint mpaint;     private float mx, my;     private static final float tolerance = 5;     private int canvasheight, canvaswidth;     private float radius;      public canvasview(context c, attributeset attrs) {         super(c, attrs);         context = c;          mpath = new path();          mpaint = new paint();         mpaint.setstrokewidth(3);         mpaint.setcolor(color.cyan);     }      // override ondraw     @override     protected void ondraw(canvas canvas) {          super.ondraw(canvas);          mcanvas=canvas;          drawable d = getresources().getdrawable(r.drawable.circle_1);          canvasheight= canvas.getheight();         canvaswidth= canvas.getwidth();          log.d("height - "," / "+canvas.getheight());         log.d("width - "," / "+canvas.getwidth());  //         displaymetrics displaymetrics = new displaymetrics(); //        ((activity)context).getwindowmanager().getdefaultdisplay().getmetrics(displaymetrics); //        int height = displaymetrics.heightpixels; //        int width = displaymetrics.widthpixels;          float h=canvasheight/2;         float w=canvaswidth/2;           d.setbounds(0, 0, canvaswidth, canvasheight);         d.draw(canvas);          canvas.drawcircle(w, h, radius, mpaint);     }      public void clear2(){         radius=0;         //important. refreshes view calling ondraw function         invalidate();      }      public void drawcircle(float radius1) {          radius=radius1;         //important. refreshes view calling ondraw function         invalidate();      }      public int getcanvasheight()     {         return canvasheight;     }      public int getcanvaswidth()     {         return canvaswidth;     }  } 

now problem , cannot draw circle loading of fragment . means circle cannot draw without button action . want when fragment loading .

have ideas ?

thank you.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -