Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何单击ListView-Robotium automation中索引在10个位置的按钮?_Java_Android_Robotium - Fatal编程技术网

Java 如何单击ListView-Robotium automation中索引在10个位置的按钮?

Java 如何单击ListView-Robotium automation中索引在10个位置的按钮?,java,android,robotium,Java,Android,Robotium,假设我有一个ListView,其中包含20个ListItems。每个项目都有一个按钮,现在我想单击ListView中位于10个位置的按钮。如何通过robotium实现自动化?尝试使用solo.clickInList(int行,int索引) 比如: solo.clickInList(10,0) 希望这有帮助 我不确定您到底想做什么,我的假设是您的列表视图中有太多的项目无法显示在屏幕上,您想单击位于第10位的按钮还是类似的?我说得对吗 如果是这样的话,我之前已经生成了一些listview帮助函数来

假设我有一个ListView,其中包含20个ListItems。每个项目都有一个按钮,现在我想单击ListView中位于10个位置的按钮。如何通过robotium实现自动化?

尝试使用solo.clickInList(int行,int索引)

比如:

solo.clickInList(10,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();
}
public View getviewatinex(final-ListView-liselement、final-int-indexInList、Instrumentation){
ListView父项=listElement;
如果(父项!=null){
如果(indexInList尝试这样做(不确定是否有效)


希望这有帮助!

家庭作业?听起来应该很简单。所以,有趣的是,告诉我如果我知道robotium会有什么解决方案。这就是为什么我保守地说“听起来像”。那么,robotium是一个Java库?如果是的话,请标记
[Java]
。假设是最新版本。我正在下载文档。谢谢…我不想单击10位置的列表,我想单击位于列表10位置的按钮。你知道区别吗?是的,我明白了。我现在无法测试它,但我认为它会起作用。你是否尝试按ID搜索按钮在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);
    //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);