Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete table row in table layout in android

void init()
{
   intcolumnwidth1 = int_scr_wd*55;
   intcolumnwidth1 = intcolumnwidth1/100;
   for (int i = 0; i < strarr.length-1; i++)
   {
      strinarr = fun1.split(strarr[i].trim(),"^");
      tr1 = (TableRow) new TableRow(this);
      txt1=new TextView(this);
      txt1.setWidth(intcolumnwidth1);
      txt1.setText(strinarr[0]);
      tr1.addView(txt1);
      tl.addView(tr1,new TableLayout.LayoutParams(layoutParams));
   }
}

Scenario is this when for the first i open this page it dynamically adds rows in the table layout ... but if after some time data in database changes ... when i click on refresh button it appends the new data after the old data in the table layout... all i need is the solution for how to refresh or delete textview that already exists in the table layout...

thanx..

like image 889
Sourabh Avatar asked Apr 05 '11 14:04

Sourabh


People also ask

How do I delete a table layout?

Click somewhere in the table. On the Table Layout (or just Table) tab, select Delete, and then select Delete Table.

Is table layout available in Android?

TableLayout is a ViewGroup that displays child View elements in rows and columns. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout. TableLayout positions its children into rows and columns.


2 Answers

Try removeView

row = (TableRow)findViewById(R.id.row);
table.removeView(row);
like image 70
SteD Avatar answered Sep 24 '22 09:09

SteD


This method I have written removes all rows except the first one. It is useful if you don't want to remove the header row, for example:

private void cleanTable(TableLayout table) {

    int childCount = table.getChildCount();

    // Remove all rows except the first one
    if (childCount > 1) {
        table.removeViews(1, childCount - 1);
    }
}
like image 34
Fer Avatar answered Sep 22 '22 09:09

Fer