Monday, December 15, 2014

How to Tableview row dainamically in Android

I want to create tableview first i want to dispay one row when user want to another row just click the create row button.

It will created row automatically using this method.

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    TableLayout tableLayout = new TableLayout(getApplicationContext());
    TableRow tableRow;
    TextView textView;

    for (int i = 0; i < 4; i++) {
        tableRow = new TableRow(getApplicationContext());
        for (int j = 0; j < 3; j++) {
            textView = new TextView(getApplicationContext());
            textView.setText("test");
            textView.setPadding(20, 20, 20, 20);
            tableRow.addView(textView);
        }
        tableLayout.addView(tableRow);
    }
    setContentView(tableLayout);
}

No comments:

Post a Comment