0

I am using onTouch method for doing some works. At first step, I want to show currentX value. However, my code does not work at all. How I resolve this issue?

 public boolean onTouch(View view, MotionEvent event) {
      int currentX = (int) event.getX();    

      if(event.getAction() == MotionEvent.ACTION_MOVE) {

        Log.d("mesage:",currentX+"");

      }
      return true;
    }
Rodrigo Borges
  • 474
  • 3
  • 10
sarah
  • 125
  • 3
  • 12

1 Answers1

0

check out this link: Detecting Common Gestures

You have there snippet like this:

View myView = findViewById(R.id.my_view); 
myView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        // your stuff     
        return true;
    }
});

do you register your listener for a view? is it separated listener or implemented in Activity or other? is it MotionEventCompat or built in? we need more code...

but you said that you need to recognize "fingers to the right side". look in my link for gestures and "Detecting All Supported Gestures" or "Detecting a Subset of Supported Gestures". onFling method is what you want (right/left you can regonize by velocityX>0 or <0)

edit: in your activity_main you should have more views. you also may set id for main viewGroup (LinearLayout/RelativeLayout?), which is in whole Activity (Screen) and get this view in findViewById, then setOnTouchLister for this particular view. but like I said above probably you need Gesture

snachmsm
  • 17,866
  • 3
  • 32
  • 74