<LinearLayout [...]
<ExpandableListView
android:id="@+id/options"
android:layout_width="match_parent"
android:groupIndicator="@null"
android:layout_height="wrap_content"
android:background="@null"
android:divider="@android:color/white"
android:scrollbarSize="0dp"
tools:visibility="gone" />
</LinearLayout>
如何使用espresso点击ExpandableListView上的孩子,其中&#34; blahblahblah&#34;是我的项目视图ID,如下例所示。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/blahblahblah"
android:orientation="vertical">
答案 0 :(得分:1)
您应该使用Espresso.onData
方法。具体方法取决于您希望如何指定要选择的ExpandableListView
项目。
通常你会使用这两种方法中的一种:
data
:Adapter
假设您的ExpandableListAdapter
数据基于MyData
个对象:
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
List<MyData> data = new ArrayList();
//... all the other stuff you need for it to work
}
您可以使用Espresso.onData
来匹配所需的记录(例如,通过匹配其toString()
方法):
onData(hasToString(containsString("example"))
.inAdapterView(withId(R.id.options))
.onChildView(withId(R.id.blablabla))
.perform(click());
(特定toString()
对象的MyData
必须包含String
"example"
)
position
:Adapter
无论您的子对象与哪个数据相关联,都要与position
中的ListView
匹配(在示例position == 0
中):
onData(anything())
.inAdapterView(withId(R.id.options))
.atPosition(0)
.onChildView(withId(R.id.blablabla))
.perform(click());