java - Android Studio: onTouchEvent either doesn't run or can't update variables -


ive been trying program app on android studio , ontouchevent doesn't seem update variables.

my variables defined in main activity not method, this:

public float touchy; public float touchx; 

my ontouchevent code this:

 public boolean ontouchevent(motionevent event) {         touchx = (float) 200.0;//event.getx(); ive tried put solid numbers     touchy = (float) 200.0;//event.gety(); doesnt seem work      return true; } 

this put test in image button "movecircle" (and yes, runs)

    public void movecircleonclick(view view) {      if (touchx >0){         you.sety(50);//<<<this see if there result: there isnt     } 

my goal when movecircleonclick run, you,(imageview) transported touchx , touchy coodinates. this

you.sety(touchy); you.setx(touchx); 

//would bounty don't have enough rep. :/

it seems implemented 'ontouchlistener' interface in mainactivity. need this. set mainactivity ontouchlistener of imageview, you.

public class mainactivity implements ontouchlistener {  ...     @override     public boolean ontouch(view v, motionevent event) {         touchx = (float) 200.0;//event.getx(); ive tried put solid numbers         touchy = (float) 200.0;//event.gety(); doesnt seem work          return true;     } ... } 

in oncreate(),

@override public void oncreate(){     ...     // imageview instance this.      imageview = (imageview) findviewbyid(r.id.imageviewid);     ...     // , set it.      you.setontouchlistener(this); } 

Popular posts from this blog