TableRow tr = new TableRow(this); TableLayout.LayoutParams tableRowParams= new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); int leftMargin=10; int topMargin=2; int rightMargin=10; int bottomMargin=2; tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); tr.setLayoutParams(tableRowParams);
// reference the table layout TableLayout tbl = (TableLayout)findViewById(R.id.RHE); // delcare a new row TableRow newRow = new TableRow(this); // add views to the row newRow.addView(new TextView(this)); // you would actually want to set properties on this before adding it // add the row to the table layout tbl.addView(newRow);
TableRow tr1 = new TableRow(this); for (Entry<String, Integer> entry : map.entrySet()) { tv.setText(entry.getKey()); tv2.setText((Integer)entry.getValue()); //Error occures here tv.setGravity(Gravity.LEFT); tv2.setGravity(Gravity.RIGHT); tr1.addView(tv); tr1.addView(tv2); tl.addView(tr1, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } }
TableLayout layout = (TableLayout)mainLayout.findViewById(R.id.my_table_layout_id); for(int i = 0; i < 10; i++) { row = new TableRow(this); View layout_number = inflater.inflate(R.layout.inflate_number, layout, false); TextView number = (TextView) layout_number.findViewById(R.id.Number); number.setTag(i); number.setText(Integer.toString(i)); row.addView(number); layout.addView(row); }
TableRow tr = new TableRow(this); tr.removeAllViews(); tr.setPadding(0,10,0,10); tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); TextView tv_item1 = new TextView(this); TextView tv_item2 = new TextView(this); TextView tv_item3 = new TextView(this);
// Retrieve some elements from the layout TableLayout table = (TableLayout)findViewById(R.id.button_table); TableRow row = (TableRow)findViewById(R.id.button_row_0); NiceButton origButton = (NiceButton)findViewById(R.id.button_0); // Prepare button 0 origButton.setId(0); origButton.setText("Button 0"); origButton.setOnClickListener(mNiceButtonClickListener); mButtonViews[0] = origButton; // Create buttons 1 to 10 for (int i = 1; i < 10; i++) { if (i % 2 == 0) { row = new TableRow(this); table.addView(row); } NiceButton button = new NiceButton(i, origButton); button.setText("Button " + i); button.setOnClickListener(mNiceButtonClickListener); mButtonViews[i] = button; row.addView(button); }
for (int i = 0; i < newslist.size(); i++) { TableRow row = new TableRow(this); row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); news1 = (news) newslist.get(i); txtview.setText(new1.getTitle()); System.out.println(new1.getTitle()); row.addView(txtview); tb.addView(row); }
/* Find Tablelayout defined in main.xml */ TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines); /* Create a new row to be added. */ TableRow tr = new TableRow(this); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); /* Create a Button to be the row-content. */ Button b = new Button(this); b.setText("Dynamic Button"); b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); /* Add Button to row. */ tr.addView(b); /* Add row to TableLayout. */ //tr.setBackgroundResource(R.drawable.sf_gradient_03); tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setup this activity's view. setContentView(R.layout.game_board); TableLayout table = (TableLayout) findViewById(R.id.table); int gridSize = 5; // Create the table elements and add to the table. int uniqueId = 1; for (int i = 0; i < gridSize; i++) { // Create table rows. TableRow row = new TableRow(this); row.setId(uniqueId++); for (int j = 0; j < gridSize; j++) { // Create buttons. Button button = new Button(this); button.setId(uniqueId++); row.addView(button); } // Add row to the table. table.addView(row); } }
foreach (news new1 : newslist) { TableRow row = new TableRow(this); row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); txtview.setText(new1.getTitle()); System.out.println(new1.getTitle()); row.addView(txtview); tb.addView(row); }
TableLayout table = new TableLayout(this); // Java. You succeed! FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); table.setLayoutParams(lp); table.setStretchAllColumns(true); TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0f); TableRow.LayoutParams cellLp = new TableRow.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0f); for (int r = 0; r < 2; ++r) { TableRow row = new TableRow(this); for (int c = 0; c < 2; ++c) { Button btn = new Button(this); btn.setText("A"); row.addView(btn, cellLp); } table.addView(row, rowLp); } setContentView(table);
TableRow tr = new TableRow(...); TableLayout.LayoutParams lp = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(10,10,10,10); tr.setLayoutParams(lp); ------ // the key is here! yourTableLayoutInstance.addView(tr, lp);
TableLayout prices = (TableLayout)findViewById(R.id.prices); prices.setStretchAllColumns(true); prices.bringToFront(); for(int i = 0; i < drug.length; i++){ TableRow tr = new TableRow(this); TextView c1 = new TextView(this); c1.setText(drug[i].getName()); TextView c2 = new TextView(this); c2.setText(String.valueOf(drug[i].getPrice())); TextView c3 = new TextView(this); c3.setText(String.valueOf(drug[i].getAmount())); tr.addView(c1); tr.addView(c2); tr.addView(c3); prices.addView(tr); }
for(int i=0 ; i < 2 ; i++) { TableRow tr = new TableRow(this); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); tr.setBackgroundResource(R.drawable.border); linearUserPicture = new View(); //DON'T COPY THIS! re create your view as you did it before every time tr.addView(linearUserPicture); // INITIALIZE linearUserPicture every loop! tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT)); }
public class MainActivity extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TableLayout layout = new TableLayout (this); layout.setLayoutParams( new TableLayout.LayoutParams(4,5) ); layout.setPadding(1,1,1,1); for (int f=0; f<=13; f++) { TableRow tr = new TableRow(this); for (int c=0; c<=9; c++) { Button b = new Button (this); b.setText(""+f+c); b.setTextSize(10.0f); b.setTextColor(Color.rgb( 100, 200, 200)); b.setOnClickListener(this); tr.addView(b, 30,30); } // for layout.addView(tr); } // for super.setContentView(layout); } // () public void onClick(View view) { ((Button) view).setText("*"); ((Button) view).setEnabled(false); } } // class
// PSEUDOCODE TableRow newRow = new TableRow(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(/*....*/); newRow.setLayoutParams(lp); relLayout.add(newRow);
HSV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); TableRow tblRow = new TableRow(this); tblRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tblRow.setBackgroundResource(R.drawable.bookshelf); imageView.setImageResource(R.drawable.book1); TextView textView = new TextView(this); textView.setText("Java Tester"); textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tblRow.addView(imageView,j); tblLayout.addView(HSV, i);
TableLayout caseTable = (TableLayout) findViewById(R.id.caseTable); TableRow caseRow = new TableRow(this); caseRow.setOrientation(TableRow.VERTICAL); EditText name = new EditText(this); //name.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); name.setText("Name __"); caseRow.addView(name); caseTable.addView(caseRow,new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));