How To Click On A Button, Which Is Indexed At 10 Position In Listview - Robotium Automation?
Suppose, I have a ListView, which contains 20 ListItems. Each item is having a button, now I want to click a button which is located at 10 position in ListView. How I can automate
Solution 1:
Try to do ti like this (not sure if it works)
//get the list viewListViewmyList= (ListView)solo.getView(R.id.list);
//get the list element at the position you wantViewlistElement= 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
Hope this helps !
Solution 2:
Try using the solo.clickInList(int line, int index)
Something like:
solo.clickInList(10,0)
Hope this helps!
Solution 3:
I am not sure exactly what you are trying to do, My assumption is that you have a list view with too many items to fit on the screen and you want to click the button that is at the 10th position or something to that effect? am i right?
If so i have previously produced some listview helper functions to get the view at a given index in the list view:
public View getViewAtIndex(final ListView listElement, finalint indexInList, Instrumentation instrumentation) {
ListViewparent= listElement;
if (parent != null) {
if (indexInList <= parent.getAdapter().getCount()) {
scrollListTo(parent, indexInList, instrumentation);
intindexToUse= indexInList - parent.getFirstVisiblePosition();
return parent.getChildAt(indexToUse);
}
}
returnnull;
}
public <T extendsAbsListView> voidscrollListTo(final T listView,
finalint index, Instrumentation instrumentation) {
instrumentation.runOnMainSync(newRunnable() {
@Overridepublicvoidrun() {
listView.setSelection(index);
}
});
instrumentation.waitForIdleSync();
}
Solution 4:
//First get the List View ListViewlist= (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:*/inti=10 ;
ViewbuttonItem= list.getAdapter().getView(i,getActivity().findViewById(R.layout.list_item),list);
solo.clickOnView(buttonItem);
Post a Comment for "How To Click On A Button, Which Is Indexed At 10 Position In Listview - Robotium Automation?"