title: Getting Id from programmatically view
body: <p>This is a sample try code. I am adding checkbox and textview in the table row by using loop. Everything is working fine except that whenever I am trying to take out(checkBox, Textview) from another method, I am not able  to get it. I don't know how to solve this. I tried setId but I couldn't get the Id.</p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
      TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
      TableRow[] row = new TableRow[5];
      TextView tv[] = new TextView[5];
      CheckBox[] cb = new CheckBox[5];
      Button clickTestRow;
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
      for(int j = 0; j &lt; 5; j ++){
          row[j] = new TableRow(this);
          tl.addView(row[j]);
          tv[j] = new TextView(this);
          cb[j] = new CheckBox(this);
  
          tv[j].setText("This is text");
  
          row[j].addView(cb[j]);
          row[j].addView(tv[j]);
  
          if(j == 0)
              cb[j].setChecked(true);
  
      }
  
      clickTestRow = (Button) findViewById(R.id.clickTestRow);
  
      clickTestRow.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
      TableLayout tlid = (TableLayout) findViewById(R.id.tableLayout1);
              for(int i = 0; i &lt; 5; i ++){
                  if(cb[i].isChecked()){
                      tlid.removeView(row[i]);
                  }
              }
          }
      });
  </code></pre>