0

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) {
            ...
            }
        }
    }
1
  • Hi, is this problem resolved? Dec 10, 2015 at 10:08

2 Answers 2

1

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

2
  • The question has too many code snippets. Use it and suggest the person where to replace/add the code clearly.
    – rajuGT
    Sep 29, 2015 at 19:48
  • Problem was solved. I have used Android Device Manager->Connected Device->Dump View Hierarchy for UI Automator and figure out what exactly i need to click. Code looks like: "onData(Matchers.allOf(Matchers.is(Matchers.instanceOf(FileListItem.class)))).atPosition(10).perform(ViewActions.click())". I have use onData as usggested above. Thanks!
    – Romasius
    Feb 9, 2016 at 14:42
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.