title: Android GridLayout Row index
body: <p>I have a design Layout like the code below,and I want to write a code for each checkbox to show me the index of the selected row when checked ,but I don't know how to fetch this property from my gridlayout dynamically and not by typing the index manually in the Toast.makeText().I'll be grateful if you help me on this issue.</p>
  
  <p>Here is my Layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="5"
    android:rowCount="4" 
    android:orientation="horizontal" 
    android:background="#FF1354"
    android:id="@+id/Grd"&gt;
    &lt;TextView android:text=" R 1, C 1 " 
         android:background="@drawable/border" /&gt;
  
    &lt;TextView 
        android:text=" R 1, C 2 "
         android:background="@drawable/border"/&gt;
  
    &lt;TextView android:text=" R 1, C 3 "
         android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 1, C 4 "
        android:background="@drawable/border" /&gt;
  
    &lt;CheckBox 
        android:id="@+id/chk1"
        android:text=""
       style="?android:attr/starStyle"  /&gt;
  
    &lt;TextView android:text=" R 2, C 1 "
        android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 2, C 2 "
        android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 2, C 3 "
        android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 2, C 4 "
         android:background="@drawable/border" /&gt;
  
    &lt;CheckBox
        android:id="@+id/chk2"
         android:text=""
     style="?android:attr/starStyle"  /&gt;
  
    &lt;TextView android:text=" R 3, C 1 "
         android:background="@drawable/border" /&gt;
    &lt;TextView android:text=" R 3, C 2 "
        android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 3, C 3 "
         android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 3, C 4 " 
        android:background="@drawable/border"/&gt;
  
    &lt;CheckBox 
        android:id="@+id/chk3"
        android:text=""
         style="?android:attr/starStyle"/&gt;
  
    &lt;TextView android:text=" R 4, C 1 "
      android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 4, C 2 "
        android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 4, C 3 "
         android:background="@drawable/border" /&gt;
  
    &lt;TextView android:text=" R 4, C 4 "
        android:background="@drawable/border" /&gt;
  
    &lt;CheckBox 
        android:id="@+id/chk4"
        android:text=""
        style="?android:attr/starStyle" /&gt;
  
  &lt;/GridLayout&gt;
  </code></pre>
  
  <p>and Here is my code:</p>
  
  <pre><code>package com.example.hiiiiiiiiiiiiii;
  
  import com.example.mynewtestoftablecheck.MyNewTestTableCheck;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.view.View;
  import android.widget.CheckBox;
  import android.widget.GridLayout;
  import android.widget.GridView;
  import android.widget.Toast;
  
  public class Hiiiiiiiiiiiiiiiiiiiiiiii extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_hiiiiiiiiiiiiiiiiiiiiiiii);
  
  
        CheckBox chk1=(CheckBox)findViewById(R.id.chk1);
        chk1.setOnClickListener(new View.OnClickListener() {
            GridLayout Grd=(GridLayout)findViewById(R.id.Grd);
  
  
          @Override
          public void onClick(View arg0) {
              {
                  if (((CheckBox) arg0).isChecked()) {
                      Toast.makeText(Hiiiiiiiiiiiiiiiiiiiiiiii.this,
                                 "1st Row checked", Toast.LENGTH_LONG).show();
                  }
                  else
                  {
                      Toast.makeText(Hiiiiiiiiiiiiiiiiiiiiiiii.this,
                              "1st Row Unchecked", Toast.LENGTH_LONG).show();
          }
                  }
  
              }
          });
  
  
  
        CheckBox chk2=(CheckBox)findViewById(R.id.chk2);
        CheckBox chk3=(CheckBox)findViewById(R.id.chk3);
        CheckBox chk4=(CheckBox)findViewById(R.id.chk4);
  
  
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_hiiiiiiiiiiiiiiiiiiiiiiii, menu);
          return true;
      }
  }
  </code></pre>