public void populate() {
TableRow tr = new TableRow(getActivity());
tr.setId(100 + count);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
Button b_add = new Button(getActivity());
b_add.setId(20);
b_add.setText("+");
b_add.setTextColor(Color.RED);
b_add.setGravity(Gravity.CENTER);
b_add.setPadding(2, 2, 2, 2);
b_add.setOnClickListener(add);
tr.addView(b_add);
TextView v_no = new EditText(getActivity());
v_no.setId(200 + count);
v_no.setHint("Vehicale NO");
v_no.setTag("adress");
v_no.setTag("v_no");
v_no.setTextColor(Color.BLACK);
v_no.setGravity(Gravity.CENTER);
tr.addView(v_no);
Button b_minus = new Button(getActivity());
b_minus.setId(20);
b_minus.setText("-");
b_minus.setTextColor(Color.RED);
b_minus.setGravity(Gravity.CENTER);
b_minus.setPadding(2, 2, 2, 2);
b_minus.setOnClickListener(remove);
tr.addView(b_minus);
// finally add this to the table row
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
count++;
}
I create this code to create a table with three columns using table layout.It works fine.But I need to remove the table rows except the first row.Can u help me to do that
while (yourTableLayout.getChildCount() > 1)
yourTableLayout.removeView(yourTableLayout.getChildAt(yourTableLayout.getChildCount() - 1);
This should iterate over your TableLayout and remove the rows one by one from the bottom to the top, until there remains just one (which won't get removed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With