假设,我有一个ListView,其中包含20个ListItems。每个项目都有一个按钮,现在我想单击位于ListView中10个位置的按钮。我如何通过robotium实现自动化?如何点击一个按钮,该按钮在ListView - Robotium自动化中的10位置索引?
回答
尝试使用solo.clickInList(INT线,诠释指数)
喜欢的东西:
solo.clickInList(10,0)
希望这有助于!
非常感谢...我不想点击10位置的列表,我想点击一个位于列表10位置的按钮。你有区别吗? – user1667968
是的,我明白了。我现在无法测试它,但我认为它会起作用。你是否试图通过ID搜索按钮,好像它不在列表中或类似的东西? – Proghero
我不知道正是你正在尝试做的,我的假设是,你有太多的项目的列表视图,以适应在屏幕上,你要点击的按钮是在第十位还是有这个效果的?我对吗?
如果是我以前产生了一些列表视图辅助函数在列表视图中给定索引处得到的观点:
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();
}
尝试做TI这样的(不知道它的工作原理)
//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
希望这有助于!
在Robotium 4.3.1中,这是无法完成的,因为solo.clickOnView()采用'int'类型参数,但solo.getView()返回'View'。 –
//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);
- 1. 如何点击一个按钮,它位于ListView中的位置2通过robotium自动化?
- 2. ListView按钮点击位置
- 3. 当我们在位置1点击ListView按钮时,第10个位置的按钮也被点击
- 4. 自动化一个JavaScript按钮点击
- 5. 如何获取在ListView中点击切换按钮的位置?
- 6. 如何在Robotium测试中点击软键盘'搜索'按钮?
- 7. 自定义对话框的按钮的位置点击ListView中
- 8. WPF:如何在点击另一个按钮时动画按钮?
- 9. jQuery按钮位置索引
- 10. JavaScript自动点击一个按钮
- 11. 自动点击一个html按钮
- 12. 在其他页面点击另一个按钮后自动点击按钮
- 13. Android的Listview按钮点击
- 14. 如何在listview中点击listview项目按钮启动相机?
- 15. 如何在Drupal7中添加一个按钮点击按钮?
- 16. 如何在Android的自动点击一个按钮,每一秒
- 17. 自动化点击提交按钮
- 18. IE9自动化按钮点击
- 19. BB 10 C++点击按钮
- 20. 按钮自动点击?
- 21. 自动点击按钮
- 22. 自动化登录一个网站,并点击一个按钮
- 23. ANDROID如何获得价值listview项目位置按钮点击
- 24. 带有按钮的Robotium ListView无法单击列表中的按钮
- 25. ListView的滚动按钮上点击
- 26. 在C#中指定时间点击一个按钮的自动触发按钮#
- 27. C# - 让4个单选按钮更改按钮位置点击
- 28. fire OnItem点击按钮时点击listview
- 29. 如何自动点击输入按钮
- 30. 按钮点击和ListView点击
家庭作业?听起来应该很容易。 –
所以,有趣的告诉我解决方案 – user1667968
如果我知道robotium,我会。这就是为什么我保守并说“听起来像”。 –