我有一个包含很多元素,即我们需要向下滚动到看到所有的元素列表视图。现在,我想要做的是,点击所有的ListView元素。我怎样才能做到这一点。现在,我使用下面的code,但它不会自动滚动。请大家帮帮忙。
的ListView L = solo.getCurrentListViews()得到(0)。
assertNotNull(没有列表视图!,L);
assertTrue(列表视图中没有!,l.getChildCount()0);
//获取最后一个列表项目
视图V = l.getChildAt(l.getChildCount());
的System.out.println(getChildCount:+ l.getChildCount());
INT I = 1;
而(ⅰ&其中; = l.getChildCount()){
solo.clickInList(ⅰ);
solo.goBack();
我++;
}
解决方案
我有previously使用这些辅助功能略有不同的状态来处理大部分我们需要和列表视图:
公开查看getViewAtIndex(最终的ListView listElement,最终诠释indexInList,仪器仪表){
ListView的父= listElement;
如果(父!= NULL){
如果(indexInList< = parent.getAdapter()getCount将()){
scrollListTo(父母,indexInList,仪器仪表);
INT indexToUse = indexInList - parent.getFirstVisiblePosition();
返回parent.getChildAt(indexToUse);
}
}
返回null;
}
公众<吨延伸AbsListView>无效scrollListTo(最终t的ListView,
最终诠释指数,仪器仪表){
instrumentation.runOnMainSync(新的Runnable(){
@覆盖
公共无效的run(){
listView.setSelection(指数);
}
});
instrumentation.waitForIdleSync();
}
有了这些你的方法是:
ListView控件列表= solo.getCurrentListViews()得到(0)。
的for(int i = 0; I< list.getAdapter()getCount将();我++){
solo.clickOnView(getViewAtIndex(列表,我,getInstrumentation()))
}
I have a listView that contains lots of elements i.e. we have to scroll down to see all the elements. Now what i want to do is, click all the listView elements. How can I do that. Right now,I am using the following code but it doesn't scroll automatically. Please help.
ListView l = solo.getCurrentListViews().get(0);
assertNotNull("No list views!", l);
assertTrue("No items in list view!", l.getChildCount() > 0);
// Get the last list item
View v = l.getChildAt(l.getChildCount());
System.out.println("getChildCount: " + l.getChildCount());
int i = 1;
while (i <= l.getChildCount()) {
solo.clickInList(i);
solo.goBack();
i++;
}
解决方案
I have previously used these helper functions in a slightly different state to handle most of what we need with listviews:
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();
}
With these your method would be:
ListView list = solo.getCurrentListViews().get(0);
for(int i=0; i < list.getAdapter().getCount(); i++){
solo.clickOnView(getViewAtIndex(list, i, getInstrumentation()))
}
上一篇:Android的 - 从应用程序内改变根深蒂固的设备的系统设置根深蒂固、系统设置、应用程序、设备
下一篇:OutOfMemoryException异常大解析JSON响应时异常、OutOfMemoryException、JSON