2012-10-19 3 views
4

20 개의 ListItem이 포함 된 ListView가 있습니다. 각 항목에 버튼이 있습니다. ListView에서 10 위치에있는 버튼을 클릭하고 싶습니다. 어떻게 로봇을 통해 자동화 할 수 있습니까?ListView - Robotium 자동화에서 10 위치에 인덱싱 된 버튼을 클릭하는 방법?

+0

숙제? 그것이 쉬운 것처럼 들리 네요. –

+0

그래서 재밌는 해결책을 말해 주렴. – user1667968

+0

만약 내가 robotium을 알고 싶을 것이다. 그래서 나는 보수적이며 "소리 같아"라고 말합니다. –

답변

0

solo.clickInList

뭔가 같은 (INT 라인, INT 지수)를 사용하여보십시오 :이 도움이

solo.clickInList(10,0) 

희망을!

http://www.jarvana.com/jarvana/view/com/jayway/android/robotium/robotium-solo/2.0.1/robotium-solo-2.0.1-javadoc.jar!/com/jayway/android/robotium/solo/Solo.html#clickInList(int,%20int)

+0

고마워요 ... 10 위치에서 목록을 클릭하고 싶지 않습니다. 목록에있는 10 위치에있는 버튼을 클릭하고 싶습니다. 그 차이가 있니? – user1667968

+0

네, 알겠습니다. 지금은 테스트 할 수 없지만 제대로 작동 할 것이라고 생각했습니다. 당신이 ID로 버튼을 검색하려고했는데 마치 목록 안에 있거나 그 안에있는 것처럼 보이지 않았습니까? – Proghero

0

나는 내 가정이 화면에 맞게 너무 많은 항목 목록보기를 가지고있다, 당신이하려는 정확히 잘 모르겠습니다 당신은에있는 버튼을 클릭합니다 10 위 또는 그런 효과가 있습니까? 내가 맞습니까?

내가 이전 목록보기에서 지정된 인덱스 뷰를 얻기 위해 몇 가지 목록보기 도우미 기능을 생산 그렇다면 : (작동 있는지 확실하지 않습니다)

public View getViewAtIndex(final ListView listElement, final int indexInList, Instrumentation instrumentation) { 
    ListView parent = listElement; 
    if (parent != null) { 
     if (indexInList <= parent.getAdapter().getCount()) { 
      scrollListTo(parent, indexInList, instrumentation); 
      int indexToUse = indexInList - parent.getFirstVisiblePosition(); 
      return parent.getChildAt(indexToUse); 
     } 
    } 
    return null; 
} 

public <T extends AbsListView> void scrollListTo(final T listView, 
     final int index, Instrumentation instrumentation) { 
    instrumentation.runOnMainSync(new Runnable() { 
     @Override 
     public void run() { 
      listView.setSelection(index); 
     } 
    }); 
    instrumentation.waitForIdleSync(); 
} 
1

시도는 다음과 같이 TI 할

//get the list view 
ListView myList = (ListView)solo.getView(R.id.list); 
//get the list element at the position you want 
View listElement = myList.getChildAt(10);// myList is local var 
//click on imageView inside that list element 
solo.clickOnView(solo.getView(listElement.findViewById(R.id.my_button)));// not double eE 

희망이 도움이됩니다.

+0

Roboium 4.3.1에서는 solo.clickOnView()가'int' 유형의 매개 변수를 사용하지만 solo.getView()가'View'를 반환하기 때문에이 작업을 수행 할 수 없습니다. –

0
//First get the List View 
    ListView list = (ListView) solo.getView(R.id.list_view); 

/*  View viewElement = list.getChildAt(10); 
     This might return null as this item view will not be created if the 10th element is 
     not in the screen. (i.e. the getView would have not been called for this view). 

     Suppose for single item list_item.xml is used then 
     Get the 10th button item view as follows:*/ 
    int i = 10 ;  

    View buttonItem = list.getAdapter().getView(i,getActivity().findViewById(R.layout.list_item),list); 

    solo.clickOnView(buttonItem); 
관련 문제