Cannot add to an imageView a gesture detector in Android -


i trying attach imageview gesture detector following code. want in first place code able color of bitmap , display message nothing. missing here? shall place in touchevent method?

public class mainactivity extends activity implements      gesturedetector.ongesturelistener,     gesturedetector.ondoubletaplistener{  private static final string debug_tag = "gestures"; private gesturedetectorcompat mdetector;   // called when activity first created.  @override public void oncreate(bundle savedinstancestate) {    super.oncreate(savedinstancestate);    setcontentview(r.layout.activity_main);     img = (imageview) findviewbyid(r.id.imageview);             mdetector = new gesturedetectorcompat(img.getcontext(),this);       mdetector.setondoubletaplistener(this);  }  @override  public boolean ontouchevent(motionevent event){      this.mdetector.ontouchevent(event);     // sure call superclass implementation     return super.ontouchevent(event); }  @override public boolean ondown(motionevent event) {      log.d(debug_tag,"ondown: " + event.tostring());      return true; }    @override public void onlongpress(motionevent event) {     log.d(debug_tag, "onlongpress: " + event.tostring());  }     @override public boolean onsingletapup(motionevent event) {    int x = (int) e.getx();                     int y = (int) e.gety();                     log.d("singletapup",string.valueof(x+" "+y));                      int pixel = bitmap.getpixel(x, y);                      if (pixel == color.parsecolor("#94e3f9")) {                         toast.maketext(mainactivity.this, "blue", toast.length_short).show();                     }                     if (pixel == color.parsecolor("#f0c828")) {                         toast.maketext(mainactivity.this, "orange", toast.length_short).show();                     }                     if (pixel == color.parsecolor("#b3522c")) {                         toast.maketext(mainactivity.this, "red", toast.length_short).show();                     }                      return true; }  @override public boolean ondoubletap(motionevent event) {     log.d(debug_tag, "ondoubletap: " + event.tostring());     return true; }  @override public boolean ondoubletapevent(motionevent event) {     log.d(debug_tag, "ondoubletapevent: " + event.tostring());     return true; }  @override public boolean onsingletapconfirmed(motionevent event) {     log.d(debug_tag, "onsingletapconfirmed: " + event.tostring());     return true; } 

}

we this.. view textview, imageview instead of
this.setontouchlistener put imageview.setontouchlistener

 img.setontouchlistener(new view.ontouchlistener() {         @override         public boolean ontouch(view v, motionevent event) {             gdetector.ontouchevent(event);             return true;         }     }); 

Comments

Popular posts from this blog

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

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

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