Romasius
Romasius

Reputation: 494

scroll new ListActivity with Espresso

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) {
            ...
            }
        }
    }

Upvotes: 0

Views: 164

Answers (2)

anuja jain
anuja jain

Reputation: 1387

This will scroll the list view till 20th item is visible.

 onData(hasEntry(equalTo(ListViewSample.ROW_TEXT),is("List item: 20")))
        .check(matches(isCompletelyDisplayed()));

Upvotes: 0

Zurv&#230;
Zurv&#230;

Reputation: 650

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

Upvotes: 1

Related Questions