scroll new ListActivity with Espresso

Issue

How to click on item that i can’t see lit7.txt?

I can’t scroll MyListActivity with Espresso and click on particular item. I would like to click on lit7.txt item, but i can’t see it on the screen. I need to scroll down. But how?

screen image with MyListActivity(DirectoryViewer) and lit7.txt

I can click on “Browse…”

Espresso.onView(Matchers.allOf(ViewMatchers.withText("Browse..."))).perform(ViewActions.click());

I can click on histo2.txt

Espresso.onView(Matchers.allOf(ViewMatchers.withText("histo2.txt"))).perform(ViewActions.click());

But how to click on item that i can’t see lit7.txt?

So, I loading my ListActivity(DirectoryViewer)

protected void onLoad(){
        Intent intent  new Intent(this, DirectoryViewer.class);
        intent.putExtra(DirectoryViewer.ASSET_DIRECTORY_LOCATION, "books");
        startActivityForResult(intent, 1);}

DirectoryViewer is:

class DirectoryViewer extends ListActivity
...
    void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String dirName  getIntent().getStringExtra(ASSET_DIRECTORY_LOCATION);
        List<ListItem> items  new ArrayList<ListItem>();
        items.add(new BrowseListItem(getString(R.string.my_browse)));//Browse...
        items.add(new HeaderItem(getString(R.string.myItems)));//ITEMS
        AssetManager am  getResources().getAssets();//files
        try {
            String[] topLevel  am.list(dirName);
            for (String folder : topLevel) {
            ...
            }
        }
    }

Solution

I’d suggest looking into the onData method which allows you to interact with information in ListViews.

Answered By – Zurvæ

Leave a Comment