【发布时间】:2017-12-16 18:21:44
【问题描述】:
我有一个 ListView,它显示来自数据库的数据。
db = new DB(this);
db.open();
String[] from = new String[]{DB.COLUMN_FIRSTNAME, DB.COLUMN_LASTNAME};
int[] to = new int[]{android.R.id.text1, android.R.id.text2};
scAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_activated_2, null, from, to, 0);
lvData = (ListView) findViewById(R.id.lvData);
lvData.setAdapter(scAdapter);
lvData.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
lvData.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
它将数据库中的名字和姓氏显示为项目列表: Click to UI
所以,今天我尝试在此应用中使用 Espresso,但找不到单击包含文本的项目的方法。
当我使用时:
onData(anything())
.inAdapterView(withId(R.id.lvData))
.atPosition(3)
.perform(click());
完美运行。但我想点击包含相应项目文本的项目。
到目前为止我尝试了什么(我在 stackoverflow、google、github 等找到的所有内容):
onView(allOf(withText("Ivan Ivanov"))).perform(click())
onData(allOf(is(instanceOf(MainActivity.class)),is("Ivan Ivanov")))
.inAdapterView(withId(R.id.lvData))
.perform(click());
onData(hasToString(startsWith("v")))
.inAdapterView(withId(R.id.lvData))
.atPosition(0).perform(click());
onData(instanceOf(MainActivity.class))
.inAdapterView(withId(R.id.lvData))
.atPosition(0)
.check(matches(hasDescendant(withText("Ivan Ivanov"))));
onData(anything()).inAdapterView(withContentDescription("Ivan Ivanov"))
.atPosition(0).perform(click());
那么,字符串“Ivan Ivanov”和包含数据库数据的项目之间是否存在差异:firstName+lastName?
【问题讨论】: