touchscreen - Android touch screen listener problem -


i've created little program show user fingers on screen, problem x,y values other fingers not being modified. doing wrong?

thank you!

public class testandoactivity extends activity implements ontouchlistener { /** called when activity first created. */ private textview txtv; private textview txtv2; private int nf = 0; private map<integer, string> info;   @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      info = new hashmap<integer, string>();      setcontentview(r.layout.main);     this.txtv = (textview)this.findviewbyid(r.id.textview);     this.txtv2 = (textview)this.findviewbyid(r.id.textview2);     this.txtv.setontouchlistener(this); }  public boolean ontouch(view v, motionevent event) {          int actioncode = event.getaction() & motionevent.action_mask;     int pid = event.getaction() >> motionevent.action_pointer_id_shift;      info.put(pid, pid + ": x=" + event.getx() + " y=" + event.gety() + " pressure=" + event.getpressure() + " size=" + event.getsize());      if (actioncode == motionevent.action_pointer_up || actioncode == motionevent.action_up)         info.remove(pid);      string total = "";     (map.entry<integer, string> e : this.info.entryset()) {         total += e.getvalue() + "\n";     }      this.txtv2.settext(total);       return true; } } 

the main cause of problem used getx() , gety() method.

getx() method returns first pointer's x position , gety() returns y position.

if want other fingers' x, y value on screen, have use these methods:

getx(int pointerid)  //get #pointerid pointer's x value gety(int pointerid)  //get #pointerid pointer's y value 

other fingers' pointerid can found way you're using:

int pid = event.getaction() >> motionevent.action_pointer_id_shift; 

or use pointer index id:

getpointerid (int pointerindex)   //pointerindex 0 getpointercount()-1 

i hope helpful you. :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -