0

This is my code which generates dynamic buttons on run time! I have tried a lot but couldn't remove the previous created dynamic buttons!

This is the code

TableLayout table = (TableLayout)findViewById(R.id.tableForButtons);
    TableRow tableRow = new TableRow (this);
    tableRow.setLayoutParams(new TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT,1.0f
            ));
    table.setId(123);
    table.addView(tableRow);


    for(int i=0 ; i<ans_length; i++)
    {
        ImageView button = new ImageView (this);
        button.setLayoutParams(new TableRow.LayoutParams(
                TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT,1.0f
                ));
        button.setImageResource(R.drawable.a);
        button.setId(i);
        tableRow.addView(button);
    }

Please help me with this and provide me the code which may remove this table layout with all its views!!!

  • Did you try to do anything to delete, would you share it pls ? – Tugrul Jul 18 '14 at 13:19
  • possible duplicate of [Add and Remove Views in Android Dynamically?](http://stackoverflow.com/questions/3995215/add-and-remove-views-in-android-dynamically) – madteapot Jul 18 '14 at 13:21
  • There's a period in the bottom row on the right. Saves having to do shift-1. – stark Jul 18 '14 at 14:41

1 Answers1

0

You need to call .removeAllViewsInLayout(); in for the root layout of the views that you want to remove. So for instance table.removeAllViewsInLayout(); should remove all the rows, but it won't remove the table-objects view.

Zezeq
  • 119
  • 7