I want to create a table
with a button
that every time it is clicked adds a tablerow
with three TextView
. For the moment I could only add to the tablerow
without TextView
, however, has the problem that when I close the application the lines created are not saved, who can help me?
This is my code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnAddItem = (Button) findViewById(R.id.addItemTableRow);
btnAddItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
TableRow row = new TableRow(MainActivity.this);
TextView t = new TextView(MainActivity.this);
t.setText("Add table row");
row.addView(t);
table.addView(row, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}
});
}
}