Code example for TableRow

Methods: addView, setLayoutParams

0
 
	public MyTableLayout(Context context) {
		super(context);
		 
		for(int i = 0; i < 15; i++){
			TableRow tr = new TableRow(context);
			tr.setLayoutParams(new android.widget.TableRow.LayoutParams(android.widget.TableRow.LayoutParams.FILL_PARENT,
					android.widget.TableRow.LayoutParams.WRAP_CONTENT));
			/* Create a Button to be the row-content. */ 
			Button b1 = new Button(context);
			b1.setText("Dynamic Button");
			b1.setLayoutParams(new android.widget.TableRow.LayoutParams(android.widget.TableRow.LayoutParams.FILL_PARENT,
					android.widget.TableRow.LayoutParams.WRAP_CONTENT));
			 
			/* Create a Button to be the row-content. */ 
			Button b2 = new Button(context);
			b2.setText("Dynamic Button");
			b2.setLayoutParams(new android.widget.TableRow.LayoutParams(android.widget.TableRow.LayoutParams.FILL_PARENT,
					android.widget.TableRow.LayoutParams.WRAP_CONTENT));
			 
			/* Add Button to row. */ 
			tr.addView(b1);
			tr.addView(b2);
			/* Add row to TableLayout. */ 
			this.addView(tr, new android.widget.TableRow.LayoutParams(android.widget.TableRow.LayoutParams.FILL_PARENT,
					android.widget.TableRow.LayoutParams.WRAP_CONTENT));
		} 
			 
		 
//		TableRow tr = new TableRow(context); 
Experience pair programming with AI  Get Codota for Java