Hello I want to click a button that will add a new button to a table row every time it is clicked. After 3 buttons have been added to the row, I want to dynamically create a new table row and add a new button to it.
I know how to add a row with a button(s) to a tableLayout if I click a button. I don’t know how to modify the table row every time I click so I can add an additional button.
Any advice would be quite helpful and appreciated.
Following is my code but this is not perfect
public class DynamicTableView extends Activity {
TableLayout mTlayout;
String[] mTextofButton = { "Dipak", "E", "I", "J", "L",
"M", "G", "R", "N", "T", "H", "P",
"K", "Y", "V" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTlayout = (TableLayout) findViewById(R.id.mTlayout);
TableRow tr=new TableRow(this);
for(int i=0;i<mTextofButton.length;i++){
Button btn=new Button(this);
btn.setText(mTextofButton[i]);
tr.addView(btn);
}
mTlayout.addView(tr);
}
}
Thanks in advance.
Use following Code:-