I am developing an android application where I need the table to refresh when an event occurs. That is when a user clicks on a button, the table should now change displaying new data. So I used removeAllViews for this purpose. I will then add the rows to the table dynamically. What is happening is, when the number of rows are less than the previous number of rows, then the new rows are displayed and below them , old rows are also displayed. Can you please tell me what needs to be done.
TableLayout tableLayout1;
public void displayPanel1(int co) // dynamically add table
{
LinearLayout ll = (LinearLayout)findViewById(R.id.asdf);
LayoutParams lp = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
for(int i=0;i<co;i++) {
TableRow tR = new TableRow(this);
for(int j=0;j<12;j++) {
TextView tv2=new TextView(this);
tv2.setText(i+j+""+"\n"+"h");
tR.addView(tv2);
}
tableLayout1.addView(tR);
}
ll.addView(tableLayout1, lp);
}
In the click event I have written tableLayout1.removeAllViews(); and callecalled displayPanel() function again