List of usage examples for android.widget TableLayout addView
@Override public void addView(View child)
From source file:com.google.adsensequickstart.DisplayInventoryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ScrollView sv = new ScrollView(getActivity()); TableLayout tl = new TableLayout(getActivity()); tl.setBackgroundColor(Color.rgb(242, 239, 233)); sv.addView(tl);/* w ww. j ava 2s .c o m*/ if (displayInventoryController == null) { return sv; } Inventory inventory = displayInventoryController.getInventory(); TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableRowParams.setMargins(1, 1, 1, 1); TableRow.LayoutParams accountLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); accountLayoutParams.setMargins(2, 1, 2, 1); TableRow.LayoutParams adCLientLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); adCLientLayoutParams.setMargins(12, 1, 2, 1); TableRow.LayoutParams adUnitChannelLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); adUnitChannelLayoutParams.setMargins(24, 1, 2, 1); for (String accountId : inventory.getAccounts()) { TableRow trow = new TableRow(getActivity()); tl.addView(trow); TextView tv = new TextView(getActivity()); tv.setText(accountId); trow.addView(tv); tv.setLayoutParams(accountLayoutParams); for (String adClient : inventory.getAdClients(accountId)) { TableRow trow2 = new TableRow(getActivity()); trow2.setBackgroundColor(Color.rgb(214, 204, 181)); tl.addView(trow2); TextView tv2 = new TextView(getActivity()); tv2.setText(adClient); trow2.addView(tv2); tv2.setLayoutParams(adCLientLayoutParams); for (String adUnit : inventory.getAdUnits(adClient)) { TableRow trow3 = new TableRow(getActivity()); trow3.setBackgroundColor(Color.rgb(251, 145, 57)); tl.addView(trow3); TextView tv3 = new TextView(getActivity()); tv3.setText(adUnit); trow3.addView(tv3); tv3.setLayoutParams(adUnitChannelLayoutParams); } for (String customChannel : inventory.getCustomChannels(adClient)) { TableRow trow3 = new TableRow(getActivity()); trow3.setBackgroundColor(Color.rgb(255, 195, 69)); tl.addView(trow3); TextView tv3 = new TextView(getActivity()); tv3.setText(customChannel); trow3.addView(tv3); tv3.setLayoutParams(adUnitChannelLayoutParams); } } } return sv; }
From source file:com.ninetwozero.battlelog.fragments.PlatoonStatsFragment.java
public void generateTableRows(TableLayout parent, List<PlatoonStatsItem> stats, boolean isTime) { // Make sure the cache is null, as well as the table being cleared cacheTableRow = null;// w w w. j a va 2 s . c o m parent.removeAllViews(); // Loop over them, *one* by *one* if (stats != null) { // The number of items (-1) as the overall is a field that shouldn't // be counted int numItems = stats.size() - 1; int avg; // Iterate over the stats for (int i = 0, max = (numItems + 1); i < max; i++) { // Set the average avg = (i == 0) ? (stats.get(i).getAvg() / numItems) : stats.get(i).getAvg(); // Is it null? cacheView = (RelativeLayout) layoutInflater.inflate(R.layout.grid_item_platoon_stats, null); // Add the new TableRow if (cacheTableRow == null || (i % 3) == 0) { parent.addView(cacheTableRow = new TableRow(context)); cacheTableRow.setLayoutParams( new TableRow.LayoutParams( TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT ) ); } // Add the *layout* into the TableRow cacheTableRow.addView(cacheView); // Set the label ((TextView) cacheView.findViewById(R.id.text_label)) .setText(stats.get(i).getLabel().toUpperCase() + ""); // If (i == 0) => Overall if (isTime) { ((TextView) cacheView.findViewById(R.id.text_average)).setText(PublicUtils.timeToLiteral(avg)); ((TextView) cacheView.findViewById(R.id.text_max)) .setText(PublicUtils.timeToLiteral(stats.get(i).getMax())); ((TextView) cacheView.findViewById(R.id.text_mid)) .setText(PublicUtils.timeToLiteral(stats.get(i).getMid())); ((TextView) cacheView.findViewById(R.id.text_min)) .setText(PublicUtils.timeToLiteral(stats.get(i).getMin())); } else { ((TextView) cacheView.findViewById(R.id.text_average)).setText(avg + ""); ((TextView) cacheView.findViewById(R.id.text_max)).setText(stats.get(i).getMax() + ""); ((TextView) cacheView.findViewById(R.id.text_mid)).setText(stats.get(i).getMid() + ""); ((TextView) cacheView.findViewById(R.id.text_min)).setText(stats.get(i).getMin() + ""); } } } else { // Create a new row parent.addView(cacheTableRow = new TableRow(context)); cacheTableRow.setLayoutParams( new TableRow.LayoutParams( TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT ) ); // Add a TextView & set it up cacheTableRow.addView(cacheView = new TextView(context)); ((TextView) cacheView).setText(R.string.info_stats_not_found); ((TextView) cacheView).setGravity(Gravity.CENTER); } }
From source file:de.uulm.graphicalpasswords.openuyi.UYIPagerAdapter.java
@Override public Object instantiateItem(View collection, int pos) { LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int page = 0; switch (pos) { case 1:/* www . j a v a 2 s . co m*/ page = R.layout.uyipage2; break; case 2: page = R.layout.uyipage3; break; default: page = R.layout.uyipage1; break; } View view = inflater.inflate(page, null); TableLayout currentTable; switch (pos) { case 1: currentTable = (TableLayout) view.findViewById(R.id.uyi_tablelayout_page2); break; case 2: currentTable = (TableLayout) view.findViewById(R.id.uyi_tablelayout_page3); break; default: currentTable = (TableLayout) view.findViewById(R.id.uyi_tablelayout_page1); break; } // Add ImageButtons to TableLayout int index = 0; for (int i = 0; i < 3; i++) { TableRow currentRow = new TableRow(view.getContext()); for (int j = 0; j < 3; j++) { ImageButton button = new ImageButton(view.getContext()); button.setBackgroundColor(Color.TRANSPARENT); button.setPadding(3, 3, 3, 3); button.setAdjustViewBounds(true); button.setOnClickListener(clickListener); button.setImageResource(picture_arrays[pos][index]); button.setId(picture_arrays[pos][index]); button.setClickable(true); index++; currentRow.addView(button); } currentTable.addView(currentRow); } ((ViewPager) collection).addView(view, 0); return view; }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void parseTables(Elements tbls) { TableLayout tl = new TableLayout(getActivity()); LayoutParams tl_prms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tl_prms.gravity = Gravity.CENTER_HORIZONTAL; tl_prms.setMargins(10, 10, 10, 0);//from w w w . j ava 2 s. c om tl.setLayoutParams(tl_prms); for (Element tbl : tbls) { Elements rws = tbl.getElementsByTag("td"); TableRow row = new TableRow(getActivity()); for (Element rw : rws) { TextView txt = new TextView(getActivity()); txt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); txt.setText(rw.text()); row.addView(txt); } tl.addView(row); } lay.addView(tl); }
From source file:com.bonsai.btcreceive.AccountFragment.java
private void addAddressRow(int tableId, int index, TableLayout table, String path, String addr, String ntrans, String btcstr, String fiatstr) { TableRow row = (TableRow) LayoutInflater.from(getActivity()).inflate(R.layout.address_table_row, table, false);/* w w w .ja v a 2s . c om*/ row.setTag(tableId); row.setId(index); row.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { int tableId = (Integer) view.getTag(); int index = view.getId(); viewAddress(tableId, index); } }); { TextView tv = (TextView) row.findViewById(R.id.row_path); tv.setText(path); } { TextView tv = (TextView) row.findViewById(R.id.row_addr); tv.setText(addr); } { TextView tv = (TextView) row.findViewById(R.id.row_ntrans); tv.setText(ntrans); } { TextView tv = (TextView) row.findViewById(R.id.row_btc); tv.setText(btcstr); } { TextView tv = (TextView) row.findViewById(R.id.row_fiat); tv.setText(fiatstr); } table.addView(row); }
From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java
private void createToolSymbolExplanationDialog() { final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_tool_legend, R.string.tool_legend);//from w w w. j av a 2s . c om TableLayout tableLayout = (TableLayout) dialog.findViewById(R.id.tool_legend_table_layout); Button dismissButton = (Button) dialog.findViewById(R.id.tool_legend_dismiss_button); for (ToolType toolType : ToolType.values()) { View toolLegendRow = rowsInterface .getToolLegendRow(getActivity(), toolType.getHexColorValue(), toolType.toString()).getView(); tableLayout.addView(toolLegendRow); } dismissButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog)); dialog.show(); }
From source file:com.df.app.procedures.CarRecogniseLayout.java
/** * //from w w w. jav a2 s. c om */ private void selectCarManually() { if (!mCarSettings.getBrandString().equals("")) { View view1 = ((Activity) rootView.getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); TextView content = new TextView(view1.getContext()); content.setText(R.string.reMatch); content.setTextSize(20f); contentArea.addView(content); setTextView(view1, R.id.title, getResources().getString(R.string.alert)); AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setView(view1) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mHideContentCallback.hideContent(); showSelectCarDialog(); } }).setNegativeButton(R.string.cancel, null).create(); dialog.show(); } else { showSelectCarDialog(); } }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
private void addButton(final String senderName, String myEmail, boolean somebodyAnswered, boolean canEdit, TableLayout tableLayout, final ButtonTO button) { TableRow row = new TableRow(this); tableLayout.addView(row); row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT, 1)); // XXX: inconsistent margin between 2 rows final Button buttonView = new Button(this); buttonView.setMinWidth(UIUtils.convertDipToPixels(this, 100)); buttonView.setText(button.caption);//from w ww . j a va 2 s . c o m buttonView.setTextColor(getResources().getColor(android.R.color.primary_text_dark)); if (somebodyAnswered) buttonView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); else { buttonView.setWidth(mDisplayWidth - UIUtils.convertDipToPixels(this, 12)); } buttonView.setTextSize(19); row.addView(buttonView); final LinearLayout container = (LinearLayout) getLayoutInflater().inflate(R.layout.message_button_detail, null); container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); boolean buttonSelectedByMe = false; for (MemberStatusTO status : mCurrentMessage.members) { if ((status.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED && ((button.id == null && status.button_id == null) || (button.id != null && button.id.equals(status.button_id)))) { getLayoutInflater().inflate(R.layout.avatar, container); ImageView avatar = (ImageView) container.getChildAt(container.getChildCount() - 1); setAvatar(avatar, status.member); if (status.member.equals(myEmail)) buttonSelectedByMe = true; int dp42 = UIUtils.convertDipToPixels(this, 42); int dp2 = UIUtils.convertDipToPixels(this, 1); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) avatar.getLayoutParams(); lp.setMargins(0, dp2, 0, 0); lp.width = dp42; lp.height = dp42; } } row.addView(container); boolean hasAction = button.action != null && !"".equals(button.action); final boolean buttonIsEnabled = canEdit && (mCurrentMessage.form != null || !buttonSelectedByMe || hasAction); buttonView.setEnabled(buttonIsEnabled); int color; if (button.id == null || mCurrentMessage.form != null && Message.POSITIVE.equals(button.id)) { color = buttonIsEnabled ? Message.GREEN_BUTTON_COLOR : Message.GREENGRAY_BUTTON_COLOR; } else if (mCurrentMessage.form != null && Message.NEGATIVE.equals(button.id)) { color = buttonIsEnabled ? Message.RED_BUTTON_COLOR : Message.REDGRAY_BUTTON_COLOR; } else { color = buttonIsEnabled ? Message.BLUE_BUTTON_COLOR : Message.BLUEGRAY_BUTTON_COLOR; } buttonView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); buttonView.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { T.UI(); executeButtonClick(button, container, true); } }); final HorizontalScrollView scroller = (HorizontalScrollView) findViewById(R.id.button_scroller); scroller.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { scroller.fullScroll(ScrollView.FOCUS_RIGHT); } }); }
From source file:de.tobiasbielefeld.solitaire.ui.statistics.HighScoresFragment.java
/** * Loads the high score list//from ww w . j ava2s. co m */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_statistics_tab2, container, false); //if the app got killed while the statistics are open and then the user restarts the app, //my helper classes aren't initialized so they can't be used. In this case, simply //close the statistics try { loadData(); } catch (NullPointerException e) { getActivity().finish(); return view; } TableLayout tableLayout = (TableLayout) view.findViewById(R.id.statisticsTableHighScores); TextView textNoEntries = (TextView) view.findViewById(R.id.statisticsTextNoEntries); if (scores.getHighScore(0, 0) != 0) { textNoEntries.setVisibility(View.GONE); } for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it if (scores.getHighScore(i, 0) == 0) { //if the score is zero, don't show it continue; } TableRow row = (TableRow) LayoutInflater.from(getContext()).inflate(R.layout.statistics_scores_row, null); TextView textView1 = (TextView) row.findViewById(R.id.row_cell_1); TextView textView2 = (TextView) row.findViewById(R.id.row_cell_2); TextView textView3 = (TextView) row.findViewById(R.id.row_cell_3); TextView textView4 = (TextView) row.findViewById(R.id.row_cell_4); textView1.setText(String.format(Locale.getDefault(), "%s %s", scores.getHighScore(i, 0), dollar)); long time = scores.getHighScore(i, 1); textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", time / 3600, (time % 3600) / 60, (time % 60))); textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.getHighScore(i, 2))); textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.getHighScore(i, 2))); tableLayout.addView(row); } return view; }
From source file:com.github.tetravex_android.fragment.HiScoreTableFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_score_table, container, false); // Set the label for the size of the board TextView tableSize = (TextView) rootView.findViewById(R.id.hi_score_board_size); tableSize.setText(mLabel);/* w w w . j a v a 2 s. com*/ TableLayout table = (TableLayout) rootView.findViewById(R.id.hi_score_table_layout); // fill the table from the database cursor if (mScoreCursor != null) { // move cursor to first row, will return false if cursor is empty if (mScoreCursor.moveToFirst()) { do { // set time from the database entry, format text TextView timeTv = new TextView(rootView.getContext()); timeTv.setText(mScoreCursor.getString(Constants.DB_TIME_COL_IDX)); timeTv.setTextAppearance(rootView.getContext(), R.style.score_table_entry); // set date from the database entry, format text TextView dateTv = new TextView(rootView.getContext()); String unixTimeStr = mScoreCursor.getString(Constants.DB_DATE_COL_IDX); long unixSeconds = Long.valueOf(unixTimeStr); Date date = new Date(unixSeconds); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(date); dateTv.setText(formattedDate); dateTv.setTextAppearance(rootView.getContext(), R.style.score_table_entry); // add the Views from the database entry to the TableLayout TableRow row = new TableRow(rootView.getContext()); row.addView(timeTv); row.addView(dateTv); table.addView(row); // add row separator View spacerView = new View(rootView.getContext()); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.width = TableLayout.LayoutParams.MATCH_PARENT; params.height = 1; spacerView.setLayoutParams(params); spacerView.setBackgroundColor(getResources().getColor(R.color.tile_bkgnd_gray)); table.addView(spacerView); // move to next row } while (mScoreCursor.moveToNext()); } } return rootView; }