Jemshit
Jemshit

Reputation: 10048

Click Button inside of List item using Robotium, android

i want to click on Button which is located inside of List Item. I tried those codes, it didnt give me error but still not doing the job. Screen:

enter image description here

I tried these code (1):

EntityListItem view2 = solo.getView(EntityListItem.class,1);
solo.clickOnView(view2.DeleteEntity);
solo.sleep(3000);

I tried these code (2):

ListView myList = (ListView)solo.getView(com.hh.android.R.id.lister);
View listElement = myList.getChildAt(0);
View alt = listElement.findViewById(com.hh.android.R.id.footer);
solo.clickOnView(alt.findViewById(com.imona.android.R.id.DeleteEntity));

I tried these code (3):

ListView myList = (ListView)solo.getView(com.hh.android.R.id.lister);
View listElement = myList.getChildAt(0);
solo.clickOnView(listElement.findViewById(com.hh.android.R.id.DeleteEntity) );

this entity list

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
    <ListView        
        android:id="@+id/lister"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@android:color/transparent"
        android:dividerHeight="10.0sp" >
    </ListView>    

This is List Item

<LinearLayout
        android:id="@+id/footer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Button
         android:layout_marginRight="20dp"
            android:id="@+id/DeleteEntity"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/ic_action_delete"/>
 </LinearLayout>

Upvotes: 2

Views: 2406

Answers (3)

C&#237;cero Moura
C&#237;cero Moura

Reputation: 2333

I coded these methods to help =)

protected View getViewAtListView(int resListViewID, int position) {
    return ((ListView) getSolo().getView(resListViewID)).getChildAt(position);
}


protected View getViewAtRowListView(int resListView, int position, int viewIDInRowView) {
    return getViewAtListView(resListView, position).findViewById(viewIDInRowView);
}


protected void clickOnViewAtRowView(int resListView, int position, int viewIDInRowView) {
    View view = getViewAtRowListView(resListView, position, viewIDInRowView);
    assertNotNull(view);
    getSolo().clickOnView(view);
}

Upvotes: 0

Nikhilesh Patve
Nikhilesh Patve

Reputation: 1870

Use this code

    ListView ListView=(ListView)solo.getView(R.id.listview);    
    View view=ListView.getChildAt(0);
    Button button=(Button)view.findViewById(R.id.button);
    solo.clickOnView(button);

Upvotes: 2

Jemshit
Jemshit

Reputation: 10048

This solved my problem :

ListView  myList = (ListView) solo.getView(com.hh.android.R.id.lister,1); //1 is ipmortant, dont know why
EntityListItem til  = (EntityListItem) myList.getChildAt(0);            
solo.clickOnView(til.DeleteEntity);

I get LIstView with list id, then i get list item object from that ListView, using index number. Then click on that item object view's button, text whatever.

Upvotes: 1

Related Questions