[英]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:
屏幕:
I tried these code (1): 我尝试了以下代码(1):
EntityListItem view2 = solo.getView(EntityListItem.class,1);
solo.clickOnView(view2.DeleteEntity);
solo.sleep(3000);
I tried these code (2): 我尝试了以下代码(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): 我尝试了以下代码(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>
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);
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. 我得到具有列表ID的LIstView,然后使用索引号从该ListView获取列表项对象。 Then click on that item object view's button, text whatever.
然后单击该项目对象视图的按钮,输入任何文字。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.