Frage

I have a list of view that are built dynamically so they all have they exact same Resource id, and no description. The only way I can distinguish the difference between them is a text that is in the same parent. I am thinking the only way would be to do it like this:

Child >> parent >> child

enter image description here

As you can see above, I can get the child MILES or CALORIES. I need to get the text from the large numbers.

War es hilfreich?

Lösung

The text from the large numbers views can be obtained. Let's suppose the layout is:

1. RelativeLayout
    0. Text View -> MILES
    1. Text View -> 0.50
2. RelativeLayout
    0. Text View -> CALORIES
    1. Text View -> 100

UiCollection resultsPage = new UiCollection(
            new UiSelector().className(android.widget.ListView.class.getName()));
UiObject resultLayout = resultsPage
            .getChildByText(new UiSelector()
                    .className(android.widget.RelativeLayout.class
                            .getName()), text); //where text can be MILES or CALORIES
UiObject score = resultLayout.getChild(new UiSelector()
            .resourceId(the resource id for the large text));
return (String) score.getText();

The idea is to isolate the two Relative layouts and search for the text within them, not the whole GUI. You can use uiautomatorviewer to look at the GUI layout. Maybe you could update the question with the detailed layout.

I could use that in order to give a more accurate answer.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top