触摸后如何检测触摸

问题描述:

我想弄清楚如何检测手指从屏幕上抬起。 Essentialy我想我的程序执行的操作,一旦手指下降,直到同一个手指了一下我到目前为止没有检测一次手指上升:触摸后如何检测触摸

for(int i = 0; i < len; i++) { 
    TouchEvent event = touchEvents.get(i); 
    if(event.type == TouchEvent.TOUCH_DOWN) { 
     while (event.type != TouchEvent.TOUCH_UP){ 
      if((event.y > 160) && ((world.batMan.getY() + world.batMan.getLength()) < 319)) { 
       world.bat.moveSouth(); 
      } 
      if((event.y < 160) && (world.batMan.getY() > 0)) { 
       world.bat.moveNorth(); 
      } 
      event = touchEvents.get(i); 
     } 
    } 
} 

解决它虽然我觉得我现在已经使它比需要更复杂!

对(INT I = 0;我< LEN;我++){

 TouchEvent event = touchEvents.get(i); 



     if (event.type == TouchEvent.TOUCH_UP) 
     { 
      System.out.println("WOOT"); 
      touchNorth = false; 
      touchSouth = false; 
     } 

     else { 


      if((event.y > 160) && ((world.bat.getY() + world.bat.getLength()) < 319) 
        | (touchSouth == true)) { 
       touchSouth = true; 


      } 

      if((event.y < 160) && (world.bat.getY() > 0) | (touchNorth == true)) { 
       touchNorth = true; 

      } 

     } 
    } 


    if((touchSouth == true) && ((world.bat.getY() + world.bat.getLength()) < 319)) { 
     world.bat.moveSouth(); 
     touchSouth = true; 
    } 

    if(touchNorth == true && (world.bat.getY() > 0)) { 
     world.bat.moveNorth(); 
     touchNorth = true; 

    } 

您有无限循环:

while (event.type != TouchEvent.TOUCH_UP){ 

... 

event = touchEvents.get(i); 
} 

i从不这个循环中递增。我很惊讶你的应用没有被系统关闭。