title: How to dynamically remove a TableRow in android
body: <p>In my program I dynamically add a TableRow that has 2 TextViews and a Button in each row. When the button is click I want to delete that row.</p>
  
  <p>This is the code that I used to dynamically make the TableRows and add them to the TableLayout:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_delete);
  
      // Show the Up button in the action bar.
      setupActionBar();
      Intent intent = getIntent();
      Bundle bundle = intent.getExtras();
      ArrayList &lt;Item&gt; items = (ArrayList &lt;Item&gt;) bundle.getSerializable("array");
      TableLayout layout = (TableLayout) findViewById(R.id.tl);
  
  
  
  
      for(int i=0; i&lt;items.size(); i++)
      {
  
          Item item = items.get(i);
  
          TextView name = new TextView(this);
          TextView price = new TextView(this);
          Button delete = new Button(this);
          delete.setText("Delete");
          delete.setOnClickListener(click);
          row = new TableRow(this);
          TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
           row.setLayoutParams(lp);
  
          name.setText(item.getName());
          price.setText(Double.toString(item.getPrice()));
          row.addView(name);
          row.addView(price);
          row.addView(delete);
  
          layout.addView(row, i);
  
  
      }
  
  
  
  
  
  }
  </code></pre>
  
  <p>How do I implement the OnClickListener so that I can delete the corresponding row in which the delete button lies?</p>