Remove Dynamically created TableRow from Android Table
<p>I have a couple dynamically created TableRows in a table...each row has 3 Textviews and a Image Button to Delete the row if the users so Wishes...Creating the rows has been sucessfully achieved but now the problem arises when the user clicks the delete button on that Row. The row does not get Deleted as expected.How do I achieve this?</p>

<p>My Code is as below</p>

<pre><code>     public void addBody(String Code,String Type,String Quantity){
    /** Create a TableRow dynamically **/
     mTblrow = new TableRow(this);

    /** Creating a TextView to add to the row **/
    TextView label = new TextView(this);
    label.setText(Code);
    label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));          
    label.setPadding(5, 5, 5, 5);
    label.setBackgroundColor(Color.GRAY);

    LinearLayout Ll = new LinearLayout(this);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);       
    params.setMargins(5, 5, 5, 5);

    Ll.addView(label,params);
    mTblrow.addView((View)Ll); // Adding textView to tablerow.

    /** Creating Qty Button **/
    TextView type = new TextView(this);
    type.setText(Type);
    type.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    type.setPadding(5, 5, 5, 5);
    type.setBackgroundColor(Color.GRAY);

    Ll = new LinearLayout(this);
    params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.setMargins(0, 5, 5, 5);
    Ll.addView(type,params);
    mTblrow.addView((View)Ll); // Adding textview to tablerow.

    /** Creating Qty Button **/
    TextView quantity = new TextView(this);
    quantity.setText(Quantity);
    quantity.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    quantity.setPadding(5, 5, 5, 5);
    quantity.setBackgroundColor(Color.GRAY);

    Ll = new LinearLayout(this);
    params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

    params.setMargins(0, 5, 5, 5);
    Ll.addView(quantity,params);
    mTblrow.addView((View)Ll); 
    /** Creating Qty Button **/
    ImageView delete = new ImageView(this);
    delete.setImageDrawable(drawable);
    delete.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    delete.setPadding(5, 5, 5, 5);

    Ll = new LinearLayout(this);
    params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

    params.setMargins(0, 5, 5, 5);
    Ll.addView(delete,params);
    mTblrow.addView((View)Ll); 


     // Add the TableRow to the TableLayout

    delete.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            //This part should handle the logic to delete the row
            //This is where am hitting a snag..Please Help
            mTable.removeView(mTblrow);


        }
    });
    mTable.addView(mTblrow, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));               

}
</code></pre>

<p>EDIT:
I tried using the below code for the on click instead</p>

<pre><code>   delete.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ((ViewManager)mTblrow.getParent()).removeView(mTblrow);

            mTable.removeViewAt(rowIndex);          

        }
    });
</code></pre>

<p>Its  however  not working as desired in that It deletes the rows from top to bottom regardless of the tablerow I delete,It always starts from top to bottom</p>
