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)); } }
// 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);
// 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); }
public void createLayout2(String product, final String beerBrand) { TableRow row = new TableRow(this); final TextView tvProduct = new TextView(getApplicationContext()); LinearLayout.LayoutParams lp_l3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, (LayoutParams.WRAP_CONTENT)); tvProduct.setLayoutParams(lp_l3); tvProduct.setText(product); row.addView(tvProduct, new TableRow.LayoutParams(1)); linearContainer.addView(row,new TableLayout.LayoutParams()); }
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); }
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); }
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);
/* 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));
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
public void init(){ TableLayout ll = (TableLayout) findViewById(R.id.displayLinear); for (int i = 0; i <2; i++) { TableRow row= new TableRow(this); TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT); row.setLayoutParams(lp); checkBox = new CheckBox(this); tv = new TextView(this); addBtn = new ImageButton(this); addBtn.setImageResource(R.drawable.add); minusBtn = new ImageButton(this); minusBtn.setImageResource(R.drawable.minus); qty = new TextView(this); checkBox.setText("hello"); qty.setText("10"); row.addView(checkBox); row.addView(minusBtn); row.addView(qty); row.addView(addBtn); ll.addView(row,i); } }
TableLayout tl=(TableLayout)findViewById(R.id.tableLayout); TableRow tr1 = new TableRow(this); tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); t1.addView(tr1); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); //LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height, weight); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0dp,LayoutParams.WRAP_CONTENT, 3); tr1.addView(ll, params); View v1= new View(this); View v2= new View(this); View v3= new View(this); ll.addView(v1, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1)); ll.addView(v2, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1)); ll.addView(v3, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1));
// child element LinearLayout mainRowLayout = new LinearLayout(this); // parent element TableRow tr = new TableRow(this); // parent element's instructions (layout params for main row) TableRow.LayoutParams lopForMainRow = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); tr.addView(mainRowLayout, lopForMainRow);
TableRow tbrow0 = new TableRow(this); TextView tv0 = new TextView(this); tv0.setText(" Sl.No "); tv0.setTextColor(Color.WHITE); tbrow0.addView(tv0); TextView tv1 = new TextView(this); tv1.setText(" Product "); tv1.setTextColor(Color.WHITE); tbrow0.addView(tv1); TextView tv2 = new TextView(this); tv2.setText(" Unit Price "); tv2.setTextColor(Color.WHITE); tbrow0.addView(tv2); tv3.setTextColor(Color.WHITE); tbrow0.addView(tv3); stk.addView(tbrow0); for (int i = 0; i < 25; i++) { TableRow tbrow = new TableRow(this); t1v.setTextColor(Color.WHITE); t1v.setGravity(Gravity.CENTER); tbrow.addView(t1v); t2v.setTextColor(Color.WHITE); t2v.setGravity(Gravity.CENTER); tbrow.addView(t2v); t3v.setTextColor(Color.WHITE);
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));
TableLayout tableLayout = new TableLayout(this); TableRow tableRow = new TableRow(this); ImageView imageView = new ImageView(this); imageView.setImageResource(R.drawable.simpleAvatar); tableRow.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); tableRow.addView(imageView); tableLayout.addView(tableRow); setContentView(tableLayout);