Searching for Rows in Android Grid View Controls

Applies to TestComplete 15.69, last modified on November 13, 2024

To perform various actions on the grid view control, first, you need to locate the row containing the cell that you are going to work with. You may also need to find a certain cell value to make sure that data has been loaded to the grid correctly, and so on. This topic describes how you can do this.

To find the needed cell within the specified grid column, you can use the FindRow method of the Android GridView object. This method returns the index of the first grid row that contains the needed record. If the row containing the specified value is not found, the method returns -1.

The example below demonstrates how you can locate a grid row by its value in a particular column. The routine obtains the grid view object, locates the grid row by using the FindRow method and touches on the found cells.

JavaScript, JScript

function Test()
{
  // Select an Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain an application
  var app = Mobile.Device().Process("com.example.myapp");

  // Obtain a grid view
  var gridViewObj = app.RootLayout("").Layout("layoutTop").GridView("gv_simple");
  
  //Locate the row
  var rowIndex = gridViewObj.FindRow(1, "Sub3");
  if (rowIndex != -1)
  {
    gridViewObj.TouchCell(rowIndex, 1);
  }
}

Python

def Test():
  # Select an Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain an application
  app = Mobile.Device().Process("com.example.myapp")

  # Obtain a grid view 
  gridViewObj = app.RootLayout("").Layout("layoutTop").GridView("gv_simple")
  
  #Locate the row
  rowIndex = gridViewObj.FindRow(1, "Sub3")
  if (rowIndex != -1):
    gridViewObj.TouchCell(rowIndex, 1)

VBScript

Sub Test()
  ' Select an Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain an application
  Set app = Mobile.Device.Process("com.example.myapp")

  ' Obtain a grid view
  Set gridViewObj = app.RootLayout("").Layout("layoutTop").GridView("gv_simple")
  
  ' Locate the row
  rowIndex = gridViewObj.FindRow(1, "Sub3")
  If rowIndex <> -1 Then
    Call gridViewObj.TouchCell(rowIndex, 1)
  End If
End Sub

DelphiScript

procedure Test();
var
  app, gridViewObj, rowIndex: OleVariant;
begin
  // Select an Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain an application
  app := Mobile.Device.Process('com.example.myapp');

  // Obtain a grid view
  gridViewObj := app.RootLayout('').Layout('layoutTop').GridView('gv_simple');

  //Locate the row
  rowIndex := gridViewObj.FindRow(1, 'Sub3');
  if rowIndex <> -1 then
  begin
    gridViewObj.TouchCell(rowIndex, 1);
  end;
end;

C++Script, C#Script

function Test()
{
  // Select an Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain an application
  var app = Mobile["Device"]["Process"]("com.example.myapp");

  // Obtain a grid view
  var gridViewObj = app["RootLayout"]("")["Layout"]("layoutTop")["GridView"]("gv_simple");
  
  //Locate the row
  var rowIndex = gridViewObj["FindRow"](1, "Sub3");
  if (rowIndex != -1)
  {
    gridViewObj["TouchCell"](rowIndex, 1);
  }
}

Simulating Actions From Keyword Tests

This topic explains how to search for the row of the grid view control in scripts. You can use the described actions in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Grid View Controls
Selecting Grid View Cells
Obtaining Cell Values in Android Grid View Controls
Iterating Through Cells in Android Grid View Controls
Android GridView Support

Highlight search results