Issue
I am working on a test case to my application, there is activity with tabs each tab has gridview in each gridView some checkboxs.
Now I'm trying to scroll in gridView in the first tab and select checkBox and then click on second tab and scroll and select checkBox here is my code
GridView gridView = (GridView) solo.getView("truck_points");
int gvCount = gridView.getCount();
int nColumn = gridView.getNumColumns();
int currentChilds = gridView.getChildCount();
int numOfSelectedItems = randomItem(gvCount);
int r = 14;
int index = r%nColumn;
scrollListTo(gridView, r, getInstrumentation());
ViewGroup viewGroup = (ViewGroup) gridView.getChildAt(index);
CheckBox checkBox = (CheckBox) viewGroup.getChildAt(0);
solo.clickOnView(viewGroup);
Log.e(TAG,checkBox.getText() + " item: "+ r+", index: "+index+", column: "+ nColumn);
//Click on Post-Trip
solo.clickOnView(solo.getView(android.widget.TextView.class, 9));
solo.sleep(1000);
solo.clickOnView(solo.getView("start",1));
GridView gridView1 = (GridView) solo.getView("truck_points");
int gvCount1 = gridView1.getCount();
int nColumn1 = gridView1.getNumColumns();
int currentChilds1 = gridView1.getChildCount();
int numOfSelectedItems1 = randomItem(gvCount1);
int r1 = 17;
int index1 = r1%nColumn1;
scrollListTo(gridView1, r1,getInstrumentation());
ViewGroup viewGroup1 = (ViewGroup) gridView1.getChildAt(index1);
CheckBox checkBox1 = (CheckBox) viewGroup1.getChildAt(0);
solo.clickOnView(viewGroup1);
Log.e(TAG,checkBox1.getText() + " item: "+ r1+", index: "+index1+", column: "+ nColumn1);
solo.sleep(3000);
scrollListTo method:
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();
}
now in the first tab it scrolling and select very well, log output:
10-05 22:41:50.786 1486-1517/? E/CheckTAG: Fifth Wheel item: 14, index: 2, column: 4
and that's right.
in tab two it does not scroll or select but view right data in log output
10-05 22:41:56.106 1486-1517/? E/CheckTAG: Front Axle item: 17, index: 1, column: 4
Can any one help please?
Solution
I don't know why, but it worked when I replaced this
GridView gridView1 = (GridView) solo.getView("truck_points");
by
GridView gridView1 = (GridView) solo.getView("truck_points",1);
Answered By - Tefa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.