假设,我有一个 ListView,其中包含 20 个 ListItem。每个项目都有一个按钮,现在我想单击一个位于 ListView 中 10 位置的按钮。我如何通过机器人实现自动化?
问问题
2160 次
4 回答
1
尝试这样做(不确定它是否有效)
//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
希望这可以帮助 !
于 2013-05-09T07:21:15.323 回答
0
我不确定您到底要做什么,我的假设是您的列表视图中有太多项目无法在屏幕上显示,并且您想单击位于第 10 位的按钮或类似的东西?我对吗?
如果是这样,我之前已经生成了一些 listview 辅助函数来获取列表视图中给定索引处的视图:
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();
}
于 2012-10-23T12:15:17.837 回答
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);
于 2014-04-29T10:20:53.097 回答
0
尝试使用 solo.clickInList(int line, int index)
就像是:
solo.clickInList(10,0)
希望这可以帮助!
于 2012-10-19T11:36:26.260 回答