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 17 package android.widget.layout.table; 18 19 import com.android.frameworks.coretests.R; 20 21 import android.app.Activity; 22 import android.os.Bundle; 23 import android.view.View; 24 import android.widget.Button; 25 import android.widget.TableLayout; 26 import android.widget.TableRow; 27 import android.widget.TextView; 28 29 /** 30 * This test adds an extra row with an extra column in the table. 31 */ 32 public class AddColumn extends Activity { 33 @Override onCreate(Bundle icicle)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