Example usage for android.widget TableRow TableRow

List of usage examples for android.widget TableRow TableRow

Introduction

In this page you can find the example usage for android.widget TableRow TableRow.

Prototype

public TableRow(Context context) 

Source Link

Document

Creates a new TableRow for the given context.

Usage

From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java

private void addRowForAnswer(final Context context, final TableLayout tableLayout,
        final DecisionTree.Question question, final DecisionTree.BaseButton answer) {
    final TableRow row = new TableRow(context);
    final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0);
    tableLayout.addView(row, params);/*from w w  w.  j av a2 s .  c o  m*/

    final LinearLayout layoutVertical = new LinearLayout(context);
    layoutVertical.setOrientation(LinearLayout.VERTICAL);

    final TextView textViewAnswer = new AppCompatTextView(context);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead);
    } else {
        //noinspection deprecation
        textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead);
    }
    textViewAnswer.setText(answer.getText());
    layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    final LinearLayout layoutHorizontal = new LinearLayout(context);
    layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL);
    final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0);
    layoutVertical.addView(layoutHorizontal, paramsHorizontal);

    final BitmapDrawable icon = getIcon(context, answer);
    final ImageView imageIcon = new ImageView(context);
    imageIcon.setImageDrawable(icon);
    layoutHorizontal.addView(imageIcon);

    final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen
    // when there are too many.
    final Singleton singleton = getSingleton();
    for (int i = 0; i < answer.getExamplesCount(); i++) {

        final String iconName = answer.getExampleIconName(question.getId(), i);
        final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName);
        final ImageButton imageExample = new ImageButton(context);
        //Remove the space between the image and the outside of the button:
        imageExample.setPadding(0, 0, 0, 0);
        imageExample.setImageDrawable(iconExample);

        //Needed to make the image expand as a transition into the SubjectViewerActivity,
        //which uses the same name in fragment_subject.xml
        ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image));

        //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP));
        //imageExample.setLayoutParams(paramsImage);
        MarginLayoutParamsCompat.setMarginStart(paramsImage,
                UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin));

        final int answerIndex = i;
        imageExample.setOnClickListener(new View.OnClickListener() {
            public void onClick(final View v) {
                // Perform action on click
                onExampleImageClicked(v, answer, answerIndex);
            }
        });

        layoutHorizontal.addView(imageExample, paramsImage);
    }

    row.addView(layoutVertical,
            new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java

@SuppressLint("NewApi")
@Override/* w ww .j  ava 2  s . com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_summary, container, false);

    final MainActivity activity = (MainActivity) getActivity();
    final Context context = activity;
    final Resources resources = context.getResources();

    // Get the model and attach a listener.
    game = activity.getGame();
    if (game != null) {
        game.addListener(mGameListener);
    }

    players = activity.getPlayers();

    // Get resources.
    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] playerTextColorsIds = new int[playerTextColorsArray.length()];
    for (int i = 0; i < playerTextColorsArray.length(); i++) {
        playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1);
    }

    // Get root view.
    ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);

    // Create table.
    tableLayout = new TableLayout(context);
    TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableLayout.setLayoutParams(tableLayoutParams);
    scrollView.addView(tableLayout);

    // Add header.
    {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.player));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.trains));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.contracts));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.bonuses));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

    }

    // Add rows.
    for (int i = 0; i < players.getNum(); i++) {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        ToggleButton toggleButton = new ToggleButton(context);
        toggleButton.setGravity(Gravity.CENTER);
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setText(playerNames[i]);
        toggleButton.setClickable(false);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i]));
        row.addView(toggleButton);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

    }

    Bundle args = getArguments();
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    drawablesArray.recycle();
    playerTextColorsArray.recycle();

    // final int index = args.getInt(ARG_INDEX);
    // final String tabSpec = args.getString(ARG_TAB_SPEC);

    return rootView;
}

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

@TargetApi(11)
private static int createStandardRow(Fragment fragment, TableLayout tableLayout, List<Stock> stocks,
        SparseArray<View> tiles, int height, int margin, int index, int row) {

    Stock stock1 = stocks.get(index);/*from w ww.j a  v a  2s .c o m*/
    Stock stock2 = (index + 1 < stocks.size()) ? stocks.get(index + 1) : null;

    if (shouldUpdateTableRow(tableLayout, row, stock1, stock2)) {
        TableRow tableRow = new TableRow(fragment.getActivity());

        boolean shouldSpanFirstTile = row % 2 != 0;
        boolean shouldSpanSecondTile = !shouldSpanFirstTile;

        if (stock2 != null) {
            View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile);
            tiles.put(index, tile1);
            tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin)
                    : getNotSpannedLayoutParams(row, height, margin));

            View tile2 = createTile(fragment, stock2, index + 1, shouldSpanSecondTile);
            tiles.put(index + 1, tile2);
            tableRow.addView(tile2,
                    shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin)
                            : getLastNotSpannedLayoutParams(row, height, margin));
        } else {
            View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile);
            tiles.put(index, tile1);
            tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin)
                    : getNotSpannedLayoutParams(row, height, margin));

            View tile2 = createTileForAddingNewStock(fragment);
            tiles.put(index + 1, tile2);
            tableRow.addView(tile2,
                    shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin)
                            : getLastNotSpannedLayoutParams(row, height, margin));
        }

        if (row < tableLayout.getChildCount()) {
            tableLayout.removeViewAt(row);
        }

        tableLayout.addView(tableRow, row);
    }

    return index + 2;
}

From source file:samsungsami.io.example.samiremotecontrol.DeviceActivity.java

/**
 * Fill the device status and info table
 *//*from w  w w .  j a  va2s .c o  m*/
void fillTable() {

    TableRow row;
    TextView t1, t2, t3;
    for (int current = 0; current < fields.size(); current++) {
        row = new TableRow(this);
        t1 = new TextView(this);
        t1.setTextColor(Color.GRAY);
        t2 = new TextView(this);
        t2.setTextColor(Color.BLACK);
        t3 = new TextView(this);
        t3.setTextColor(Color.BLACK);

        t1.setText(fields.get(current));
        t2.setText(values.get(current));
        t3.setText(units.get(current));

        t1.setTextSize(15);
        t2.setTextSize(15);
        t3.setTextSize(15);

        row.addView(t1);

        if (fields.get(current).equals("state")) {
            Switch toggle = new Switch(this);
            toggle.setChecked(values.get(current).toLowerCase().equals("on"));
            toggle.setEnabled(false);
            row.addView(toggle);
        } else
            row.addView(t2);

        row.addView(t3);
        propertiesTableLayout.addView(row, new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        // Adjust the view
        propertiesTableLayout.setColumnStretchable(0, true);
        propertiesTableLayout.setColumnStretchable(1, true);
        propertiesTableLayout.setColumnStretchable(2, true);
    }
}

From source file:de.uulm.graphicalpasswords.opentapi.TAPICreatePasswordActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tapi_create_password);

    // Show the Up button in the action bar.
    setupActionBar();/*w  w w  .java2  s .  c  o  m*/

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    length = Integer.parseInt(sharedPref.getString("tapi_length", "6"));
    input = new String[length];

    // Save Pictures in randomized order
    SharedPreferences.Editor editor = sharedPref.edit();
    Random random = new Random(System.currentTimeMillis());
    boolean[] usedImages = new boolean[TAPIActivity.IMAGES.length];
    Arrays.fill(usedImages, false);
    for (int i = 0; i < TAPIActivity.IMAGES.length; i++) {
        boolean pictureSet = false;
        int index = random.nextInt(TAPIActivity.IMAGES.length);
        do {
            if (!usedImages[index]) {
                editor.putInt("image" + i, TAPIActivity.IMAGES[index]);
                pictureSet = true;
                usedImages[index] = true;
            } else if (index == TAPIActivity.IMAGES.length - 1) {
                index = 0;
            } else {
                index++;
            }
        } while (!pictureSet);
    }
    editor.commit();

    for (int i = 0; i < images.length; i++) {
        images[i] = sharedPref.getInt("image" + i, 0);
    }

    EditText editText = (EditText) findViewById(R.id.tapi_edittext);
    text = editText.getText();
    back = (Button) findViewById(R.id.tapi_back);
    save = (Button) findViewById(R.id.tapi_save);

    TableLayout table = (TableLayout) findViewById(R.id.tapi_imagetable);

    LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    TableRow row = null;
    for (int i = 0; i < imageViews.length; i++) {
        if (i % 4 == 0) {
            row = new TableRow(this);
        }
        imageViews[i] = new PassImageView(this);
        imageViews[i].setLayoutParams(layoutParams);
        imageViews[i].setAdjustViewBounds(true);
        imageViews[i].setScaleType(ScaleType.CENTER_INSIDE);
        imageViews[i].setPadding(5, 5, 5, 5);
        imageViews[i].setImageResource(images[i]);
        row.addView(imageViews[i]);
        if (i % 4 == 3) {
            table.addView(row);
        }
        imageViews[i].setOnTouchListener(new TAPIOnTouchListener(this, imageViews[i]));
    }

    Bundle bundle = new Bundle();
    bundle.putInt("length", length);
    DialogFragment intro = new IntroDialogFragment();
    intro.setArguments(bundle);
    intro.show(getFragmentManager(), "intro");
}

From source file:org.steveleach.scoresheet.ui.PlayersFragment.java

private void addHeaders() {
    TableRow headers = new TableRow(getActivity());
    addHeader(getString(R.string.playersNumHeader), headers, widths[0]);
    addHeader(getString(R.string.playersNameHeader), headers, widths[1]);
    addHeader(getString(R.string.playersActiveHeader), headers, widths[2]);
    headers.setBackgroundColor(getResources().getColor(R.color.applight));
    headers.setPadding(2, 2, 2, 2);//from   w  ww.  ja  v  a  2  s.c  om
    playersTable.addView(headers);
}

From source file:com.karthikb351.vitinfo2.fragment.grades.GradesFragment.java

void fillGradeCountData() {
    for (int i = 0; i < gradeCounts.size(); i++) {

        TableRow row = new TableRow(getActivity());
        row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        row.addView(createTextView(gradeCounts.get(i).getGrade()));
        row.addView(createTextView(Integer.toString(gradeCounts.get(i).getCount())));
        gradeCountTable.addView(row);//from   w  ww .j av a2  s .  c  o m
    }
}

From source file:mx.udlap.is522.tedroid.activity.ScoresActivity.java

/** @return una fila con el texto de que no hay puntajes. */
private TableRow emptyScoresRow() {
    TableRow row = new TableRow(this);
    TextView noScoresText = new TextView(this);
    noScoresText.setText(R.string.no_scores_message);
    applyPrimaryStyleTo(noScoresText);/*from  w w w  . ja  v  a  2  s. c o m*/
    row.addView(noScoresText);
    return row;
}

From source file:info.semanticsoftware.semassist.android.activity.SemanticResultsActivity.java

/** Presents the results in a list format.
 * @param savedInstanceState saved instance state
 *//*from www.  j a v a 2s. c  o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String resultsXML = getIntent().getStringExtra("xml");
    Vector<SemanticServiceResult> results = ClientUtils.getServiceResults(resultsXML);
    setContentView(R.layout.results);

    TableLayout tblResults = (TableLayout) findViewById(R.id.tblResultsLayout);
    tblResults.setStretchAllColumns(true);

    TableRow resultRow;
    TextView txtContent;
    TextView txtType;
    TextView txtStart;
    TextView txtEnd;
    TextView txtFeats;

    if (results == null) {
        // handle server errors
    } else {
        for (SemanticServiceResult current : results) {
            if (current.mResultType.equals(SemanticServiceResult.ANNOTATION)) {

                List<AnnotationInstance> annots = ServerResponseHandler.createAnnotation(current);
                for (int i = 0; i < annots.size(); i++) {
                    resultRow = new TableRow(getApplicationContext());

                    txtContent = new TextView(getApplicationContext());
                    txtContent.setText(annots.get(i).getContent());
                    txtContent.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtContent);

                    txtType = new TextView(getApplicationContext());
                    txtType.setText(annots.get(i).getType());
                    txtType.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtType);

                    txtStart = new TextView(getApplicationContext());
                    txtStart.setText(annots.get(i).getStart());
                    txtStart.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtStart);

                    txtEnd = new TextView(getApplicationContext());
                    txtEnd.setText(annots.get(i).getEnd());
                    txtEnd.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtEnd);

                    txtFeats = new TextView(getApplicationContext());
                    txtFeats.setText(annots.get(i).getFeatures());
                    txtFeats.setTextAppearance(getApplicationContext(), R.style.normalText);
                    resultRow.addView(txtFeats);

                    tblResults.addView(resultRow);
                }
            } else if (current.mResultType.equals(SemanticServiceResult.BOUNDLESS_ANNOTATION)) {
                //TODO find an actual pipeline to test this with
            } else if (current.mResultType.equals(SemanticServiceResult.FILE)) {
                fileName = current.mFileUrl;
                fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
                Log.d(Constants.TAG, fileName);
                getFileContentTask task = new getFileContentTask();
                task.execute(SemanticAssistantsActivity.serverURL);
            }
        }

        // reduce the number of allowed requests by one
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String strReqNum = settings.getString("reqNum", "0");
        try {
            int intReqNum = Integer.parseInt(strReqNum);
            Editor editor = settings.edit();
            intReqNum--;
            editor.putString("reqNum", Integer.toString(intReqNum));
            boolean result = editor.commit();
            if (result) {
                Log.d(Constants.TAG, "Successfully reduced the reqNum");
            } else {
                Log.d(Constants.TAG, "Cannot reduced the reqNum");
            }
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    } //else

}

From source file:com.airflo.FlightDetailFragment.java

/**
 * Method to build and add the View. It will consider preferences for
 * certain items, textsizes, and handle empty fields.
 *//* w ww  .java2  s .  com*/
public void addViews() {
    table.setColumnShrinkable(1, true);

    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(OnlyContext.getContext());
    float detSize = Float.valueOf(sharedPrefs.getString("detailtextsize", "20"));
    boolean hideEmpty = sharedPrefs.getBoolean("detailListPrefEmpty", true);
    for (Identi identi : FlightData.identis.getIdentis()) {
        String prefKey = "detailListPref" + identi.getKey();
        if (sharedPrefs.getBoolean(prefKey, true)) {
            if (hideEmpty) {
                if (mItem.getFromKey(identi.getKey()) == null)
                    continue;
                if (mItem.getFromKey(identi.getKey()).equals(""))
                    continue;
            }
            if (identi.getKey().equals("tag")) {
                if (mItem.getFromKey(identi.getKey()).length() > 0) {
                    LinearLayout lnn = (LinearLayout) rootView.findViewById(R.id.LinearAdditionLayout);
                    String[] tags = mItem.getFromKey(identi.getKey()).split(";");
                    for (String tag : tags) {
                        if (tag.equals("off-field"))
                            tag = "off_field";
                        int resID = getResources().getIdentifier(tag, "drawable", "com.airflo");
                        ImageView img = new ImageView(getActivity());
                        img.setImageResource(resID);
                        img.setPadding(8, 14, 8, 0);
                        lnn.addView(img);
                    }
                }

            } else {
                TableRow row = new TableRow(getActivity());

                header = new TextView(getActivity());
                header.setSingleLine();
                header.setTextSize(detSize);
                header.setText(identi.getStringRep());
                header.setPadding(6, 4, 10, 4);
                row.addView(header);

                cell = new TextView(getActivity());
                cell.setSingleLine(false);
                cell.setTextSize(detSize);
                cell.setText(mItem.getFromKey(identi.getKey()));
                cell.setPadding(6, 4, 6, 4);
                row.addView(cell);

                table.addView(row);
            }

        }
    }
}