0

I am writing an Android JUnit test that iterates through a list of MotionEvents and dispatches them to the Activity under test. For most events, I can just use the activity.dispatchTouchEvent(MotionEvent) method. For dialogs, I have to obtain the dialog in memory and call the dispatchTouchEvent directly. I am having trouble with android.widget.Spinner objects. The dispatchTouchEvent method seems to getting ignored.

For example, a Spinner (Mode = DIALOG) appears on the screen, the test code is dispatching a MotionEvent with the proper (x, y) coordinates and actions (ACTION_DOWN followed by ACTION_UP):

Spinner spinner = (Spinner) activity.findViewById(R.id.spinnerId);
spinner.dispatchTouchEvent(motionEvent); //returns true, but Spinner has not been touched

View v = spinner.getChildAt(0);
v.dispatchTouchEvent(motionEvent);  //returns false, Spinner has not been touched

For now, I'm using Robotium to directly click the Spinner, but this is not desired for long term. Any suggestions?

  • why don't you use spinner.performClick(); instead of spinner.dispatchTouchEvent(motionEvent); ? – maszter Mar 13 '13 at 16:42
  • The idea is to capture all of the motion events. (e.g. ACTION_DOWN, ACTION_UP, ACTION_MOVE). The user might scroll through the Spinner before making a choice. – diggybub Mar 14 '13 at 19:11

1 Answers1

0

So maybe you could do dispatch event on Activity level passing as x,y for instance center of spinner(Robotium do that but passing motionEvent via Instrumentation rather then activity).

Krzysiek
  • 599
  • 4
  • 14