views:

20

answers:

0

I am writing my android JUnit tests in InstrumentationTestCase class. I need to scroll a list view to the next screen for several verifications. One of the scenarios where I need to scrool is given below.

Say there are 25 entries and each screen can fit 10 entries. I need to iterate through the list and click the info button associated with each item on the list and do some verifications. It works fine for all the items on the first screen, but when the button to be clicked is for the 11th and subsequent items in the list, it fails, so I need to scroll to the next screen.

I was hoping that calling TouchUtils.dragQuarterScreenUp(this, activity) 4 times would scroll one full screen, but it is not scrolling exactly one screen.

I tried TouchUtils.dragViewToY by giving the offset by calculating:

In the code below, listView is the ListView that displays all the items and viewChild's value is listView.getChildAt(theLoopCounter):

int iScrollToY = viewChild .getHeight() * (listView.getChildCount() + 1); //assuming this is the Y coordinate of the 1st item on the next screen

I tried several other values to pass to the y coordinate, they all scroll but not by the value that I need. I see that TouchUtils has a lot of drag methods, I am sure one of them can scroll by the number of items in the list, but I am unable to figure out what to pass to the pixel values for these drag/scroll methods.

when I try to use listView.scrollTo(x, y) with some values that I thought would work, give the following error as the list view is not created by my code but I am just testing the existing code:

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

Can somebody please let me know the Y coordinate value that I need to pass to one of these drag/scroll methods in TouchUtils to be able to iterate through each item in the list( by either scrolling one item at a time or one whole screen after visiting all the items on one screen) or any other means to just scroll the ListView by passing as an argument the number of list items to scroll.

Thank you very much for reading this long post.