4

I have some code to check onTouchEvent on an ImageView

public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            Log.d("M", "down");
        }
        if(event.getAction() == MotionEvent.ACTION_MOVE) {
            Log.d("M", "moved");
        }
        return super.onTouchEvent(event);
    }

But I am unable to test this on emulator. Can someone help me out

prateeksarda
  • 949
  • 1
  • 10
  • 15

1 Answers1

0

Touch events should be emulated already (no pun intended) with the mouse. Try setting your listener like this:

 yourImageView.setOnTouchListener(new OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return false;
            }
       });

Taken from this previous question.

Community
  • 1
  • 1
crocboy
  • 2,887
  • 2
  • 22
  • 25
  • actually I am overriding onTouchEvent method from View class – prateeksarda Nov 09 '12 at 20:48
  • Your method is `onTouchEvent(MotionEvent e)`. The one I suggested is `onTouch(View v, MotionEvent e`). They're two different methods, and I've never seen the first one used, so I figured it might be worth a try. – crocboy Nov 09 '12 at 20:54
  • In fact, I just tried my method on the emulator, and everything worked fine. – crocboy Nov 09 '12 at 21:00