invalidate() does not call onDraw(), Android Studio -


i'm new in android , need help. in code use ontoucheven() move imageview, invalidate() doesn't call ondraw(). i'm looking solution on internet , stil can't see mistake. please, help.

map - imageview want drag.

public class mainactivity extends appcompatactivity {     textview infospace;     imageview map;     imagebutton updatebutton;     string currentdatetimestring;      @override     protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(com.example.eleizo.firstapplication.r.layout.activity_main);           map = (imageview) findviewbyid(r.id.map);          map.setwillnotdraw(false);         map.setontouchlistener(new view.ontouchlistener(){             @override             public boolean ontouch(view v, motionevent event){                 context context = getapplicationcontext();                 new customimageview(context).ontouchevent(event);                 return true;             }         });      }      private class customimageview extends view {      private float mlasttouchx;     private float mlasttouchy;     private float mposx;     private float mposy;      //the active pointer 1 moving object     private static final int invalid_pointer_id = -1;     private int mactivepointerid = invalid_pointer_id;          public customimageview(context context) {             super(context);         }          @override         public boolean ontouchevent(motionevent ev) {             final int action = ev.getactionmasked();               switch (action & motionevent.action_mask) {                 case motionevent.action_down: {                     log.d("debug","motionevent.action_down");                     final float x = ev.getx();                     final float y = ev.gety();                     mlasttouchx = x;                     mlasttouchx = y;                     mactivepointerid = ev.getpointerid(0);                     break;                 }                  case motionevent.action_move: {                     log.d("debug","motionevent.action_move");                     final int pointerindex = ev.findpointerindex(mactivepointerid);                     final float x = ev.getx(pointerindex);                     final float y = ev.gety(pointerindex);                     final float dx = x - mlasttouchx;                     final float dy = y - mlasttouchy;                     mposx += dx;                     mposy += dy;                     this.setx(x+mposx);                     this.sety(y+mposy);                      invalidate();                     log.d("debug",string.format("after invalidate(): %f %f", mposx,  mposy));                      mlasttouchx = x;                     mlasttouchy = y;                      break;                 }                  case motionevent.action_up: {                     log.d("debug","motionevent.action_up");                     mactivepointerid = invalid_pointer_id;                     break;                 }                  case motionevent.action_cancel: {                     log.d("debug","motionevent.action_cancel");                     mactivepointerid = invalid_pointer_id;                     break;                 }                  case motionevent.action_pointer_up: {                     log.d("debug","motionevent.action_pointer_up");                     final int pointerindex = ev.getactionindex();                     final int pointerid = ev.getpointerid(pointerindex);                      if (pointerid == mactivepointerid) {                         // our active pointer going up. choose new                         // active pointer , adjust accordingly.                         final int newpointerindex = pointerindex == 0 ? 1 : 0;                         mlasttouchx = ev.getx(newpointerindex);                         mlasttouchy = ev.gety(newpointerindex);                         mactivepointerid = ev.getpointerid(newpointerindex);                     }                     break;                 }             }             return true;         }          @override         protected void ondraw (canvas canvas){             log.d("debug","ondraw()");             super.ondraw(canvas);             canvas.save();             canvas.translate(mposx,mposy);             canvas.restore();          }     } 

when touch map can see log "after invalidate():.."
never can see log "ondraw()".

new customimageview(context).ontouchevent(event); 

you're not saving reference customimageview object. you're creating object, calling ontouchevent yourself, you're not storing reference or giving reference whichever class calls ondraw.

maybe make map object of type customimageview rather imageview


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -