title: Control scroll view when having two listview
body: <p>I'm using uiautomator to turn on the WiFi switch and then connect to WiFi AP.<br>
  What I want to do is:</p>
  
  <ol>
  <li>Turn on WiFi</li>
  <li>Connect to WiFi AP</li>
  </ol>
  
  <p><strong>But the problem is the setting page in tablet have two listview.</strong><br>
  When I turning on WiFi, I need to control the left listview.<br>
  And after that, I need to control the right listview to connect to my WiFi AP.</p>
  
  <p><strong>I need to scroll to browse all listview item</strong>, but I always fail to do so.<br>
  I did try to specify listview by instance(0) &amp; instance(1), but sometimes it would fail.</p>
  
  <p>Below is the code:</p>
  
  <pre><code>public void TurnOn()
  {
      try {
          UiScrollable settingsList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(0).scrollable(true));
          UiObject btItem = settingsList.getChildByText(new UiSelector().className(android.widget.LinearLayout.class.getName()),"Wi-Fi", true);
          UiObject btSwitch = btItem.getChild(new UiSelector().className(android.widget.Switch.class.getName()));
          if(!btSwitch.isChecked())
          {
              btSwitch.click();
              sleep(3000);
          }
          else System.out.println("Wifi is already enabled");
  
      } catch (UiObjectNotFoundException e) {
          System.out.println("Can't find the Wi-Fi switch");
      }
  }
  public void ConnectAP()//No password Ap
  { 
      UiScrollable wifiList = new UiScrollable(new UiSelector().className(android.widget.ListView.class.getName()).instance(1).scrollable(true));
      if(!wifiList.exists()) wifiList = new UiScrollable(new UiSelector().scrollable(true));
      else System.out.println("Its tablet");
  
      UiSelector selector = new UiSelector().className(android.widget.RelativeLayout.class.getName());
      UiObject btItem = null;
      int maxSearchSwipes = wifiList.getMaxSearchSwipes();
      for (int i = 0; i &lt; maxSearchSwipes &amp;&amp; i&lt;10; i++) 
      {
          try {
              btItem = wifiList.getChildByText(selector, "Guest");
              if(btItem.getChildCount()==2) System.out.println("Wifi is already connected to Guest AP or not in range.");
              else {
                  btItem.clickAndWaitForNewWindow();          
                  sleep(3000);
              }
              break;
          } catch (UiObjectNotFoundException e) { //Do nothing    
          }
          for (int j = 0; j &lt; i; j++){
              try {
                  wifiList.scrollForward();
              } catch (UiObjectNotFoundException e) {
                  System.out.println("Can't scrollForward");
              }
          }
      }
      if(btItem == null) System.out.println("Can't find Guest AP.");
  }
  </code></pre>
  
  <p>Most of the time it works, but sometime the code get control over the wrong listview.<br>
  Need some valuable suggestions.
  Thanks all!</p>