• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps onTouchEvent code snippet

TheCompBoy

Android Enthusiast
This is a small snippet for the onTouchEvent and this is prettymuch how you handle touch events on your phone.. Try experiment with it :)

Code:
public boolean onTouchEvent(MotionEvent e, MapView mv){
        int i = e.getAction();
        
        switch(i){
        
        case MotionEvent.ACTION_DOWN:
            //When your finger touches the screen
            
            break;
            
        case MotionEvent.ACTION_UP:
            //When your finger stop touching the screen
            
            break;
            
        case MotionEvent.ACTION_MOVE:
            //When your finger moves around the screen
            
            break;
        }
        
        return false;
    }
 
This is telling you that if the finger is touched down you can do something

And if the finger was released from the screen do something else

And if it recognises that the finger was moved around the screen you can tell it to do something..

Hope it was usefull :)
 
Back
Top Bottom