1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget.layout.table;
18
19import com.android.frameworks.coretests.R;
20
21import android.app.Activity;
22import android.os.Bundle;
23import android.view.View;
24import android.widget.Button;
25import android.widget.TableLayout;
26import android.widget.TableRow;
27import android.widget.TextView;
28
29/**
30 * This test adds an extra row with an extra column in the table.
31 */
32public class AddColumn extends Activity {
33    @Override
34    protected void onCreate(Bundle icicle) {
35        super.onCreate(icicle);
36        setContentView(R.layout.add_column_in_table);
37
38        final Button addRowButton = (Button) findViewById(R.id.add_row_button);
39        addRowButton.setOnClickListener(new View.OnClickListener() {
40            public void onClick(View v) {
41                final TableLayout table = (TableLayout) findViewById(R.id.table);
42                final TableRow newRow = new TableRow(AddColumn.this);
43                for (int i = 0; i < 4; i++) {
44                    final TextView view = new TextView(AddColumn.this);
45                    view.setText("Column " + (i + 1));
46                    view.setPadding(3, 3, 3, 3);
47                    newRow.addView(view, new TableRow.LayoutParams());
48                }
49                table.addView(newRow, new TableLayout.LayoutParams());
50                newRow.requestLayout();
51            }
52        });
53    }
54}
55