2014-10-16 3 views
5

ich folgenden Code get Kind von uiautomator verwenden, aber nicht funktioniertUIautomator wie Kind zu erhalten, indem Index oder Instanz

UiObject my = new UiObject(new UiSelector().className("android.widget.LinearLayout").instance(2)); 

    int cound = my.getChildCount(); 
    for(int i = cound - 1; i >= 0; i--) { 
     UiObject childmy2 = my.getChild(my.getSelector().childSelector(new UiSelector().instance(i))); 
     Log.e("xface", "childmy2=" + childmy2.getClassName()); 
     Log.e("xface", "childmy2=" + childmy2.getBounds().toString()); 
    } 

kann mir jemand helfen?

simplyfy meine Frage: wie die Umsetzung dieser Funktion:

Arraylist getAllChild (UIObject- Knoten)

Eingang: gegebenen Knoten Sie

Rückkehr nach GetChild wollen: alle das Kind des gegebenen Knoten

Antwort

7

Angenommen, Sie haben:

<parent> 
    <child1> 
      <child1.1></child1.1> 
      <child1.2></child1.2> 
    </child1> 
    <child2> 
      <child2.1></child2.1> 
      <child2.2></child2.2> 
    </child2> 
    <child3> 
      <child3.1></child3.1> 
      <child3.2></child3.2> 
    </child3> 
</parent> 

Bellow Lösung wird das Ergebnis Kind 1, Kind 2, Kind 3

UiObject object = new UiObject(<UiSelector for Parent>); 
int cnt = object.getChildCount(); 
for(int i = 0; i < cnt; i++) { 
    UiObject eachItem = object.getChild(new UiSelector().index(i)); 
} 

Wenn Sie Kind 1.1, Kind 1.2 und Kind 2,1

UiObject object = new UiObject(<UiSelector for Parent>); 
int cnt = object.getChildCount(); 
for(int i = 0; i < cnt; i++) { 
    UiObject eachItem = object.getChild(new UiSelector().index(i)) 
           .getChild(<UiSelector for child 1.1 or child 1.2 ...>); 
// Note: Before getting this you should check whether it has any child or not. 
} 
zurückkehren