java - Can't get OnTouchListner to work -


i trying create first android game (in eclipse) , cannot seem ontouchlistner work, because don't know how or create it. trying figure out taps screen. can please tell me how , create ontouchlistner!

activity class:

package com.gregsapps.fallingbird;  import android.app.activity; import android.os.bundle; import android.view.motionevent; import android.view.view; import android.view.view.ontouchlistener;  public class game extends activity implements ontouchlistener{      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(new gameview(this));     }     @override     public boolean ontouch(view v, motionevent event) {         // todo auto-generated method stub         if(event.getaction() == motionevent.){             system.out.println("touch");         }         return false;     }  } 

view class:

package com.gregsapps.fallingbird;  import android.r; import android.annotation.suppresslint; import android.content.context; import android.graphics.canvas; import android.view.motionevent; import android.view.view;  public class gameview extends view{      private bird bird;     private boolean runonce = false;     private context context;      public gameview(context context) {         super(context);         this.context = context;         this.setdrawingcacheenabled(true);         // todo add setup code     }      protected void ondraw(canvas canvas){         update(canvas);         //todo add drawing code         this.builddrawingcache();         //bird.canvasimage = this.getdrawingcache(true);         canvas.drawbitmap(bird.image, bird.x, bird.y, null);         system.out.println("drawing");         invalidate();     }      private void update(canvas canvas){         //todo add code update stuff         if(runonce == false){             bird = new bird(canvas, com.gregsapps.fallingbird.r.drawable.bird, context);             runonce = true;         }         bird.move();     }    } 

implement :-

public class game extends activity implements ontouchlistener{     gameview gv;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         gv = new gameview(this);         setcontentview(gv);          gv.setontouchlistener(this);     }     @override     public boolean ontouch(view v, motionevent event) {         // todo auto-generated method stub         if(event.getaction() == motionevent.action_down){             int x = event.getx();             int y = event.gety();             system.out.println("touched view @ x: " + x + " y: " + y );         }         return false;     }  } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -