Example usage for android.widget TableLayout addView

List of usage examples for android.widget TableLayout addView

Introduction

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

Prototype

@Override
public void addView(View child) 

Source Link

Usage

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleLink(Member membre) {
    //On vide les lments
    linkLayout.removeAllViews();// ww w .  jav  a2 s .  com

    //On affiche les liens que si on a recuperer des choses
    if (membre != null && membre.getSharedLinks() != null && !membre.getSharedLinks().isEmpty()) {

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null && membre.getSharedLinks().size() > 0) {
            for (final Link link : membre.getSharedLinks()) {
                RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView link_text = (TextView) row.findViewById(R.id.link_text);
                link_text.setText(Html.fromHtml(String.format("%s : <a href=\"%s\">%s</a>", link.getRel(),
                        link.getHref(), link.getHref())));
                link_text.setBackgroundColor(Color.TRANSPARENT);
                link_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(link.getHref()));
                        getActivity().startActivity(in);
                    }

                });
                tableLayout.addView(row);
            }
        } else {
            RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
            row.setBackgroundResource(R.drawable.row_transparent_background);
            //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
            TextView link_text = (TextView) row.findViewById(R.id.link_text);
            link_text.setText("Aucun lien");
            link_text.setBackgroundColor(Color.TRANSPARENT);
            tableLayout.addView(row);
        }
        linkLayout.addView(tableLayout);
    } else {
        titleLinks.getLayoutParams().height = 0;
    }
}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * @param fieldTable/*  ww  w. j a  v  a 2  s  .  c  o  m*/
 * @param nameOfField
 * @param field
 */
private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal,
        final String fieldRemote) {
    if (mCurrentLocal == null || mCurrentSugar == null)
        return;
    // String fieldLocal = mCurrentLocal.get(nameOfField);
    // String fieldRemote = mCurrentSugar.get(nameOfField);
    TableRow row = new TableRow(this);
    final Spinner sourceSelect = new Spinner(this);
    sourceSelect.setBackgroundResource(R.drawable.black_underline);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources));
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sourceSelect.setAdapter(spinnerArrayAdapter);
    // Open the spinner when pressing any of the text fields
    OnClickListener spinnerOpener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            sourceSelect.performClick();
        }
    };
    row.addView(sourceSelect);
    fieldTable.addView(row);
    row = new TableRow(this);
    TextView fieldName = new TextView(this);
    int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName());
    fieldName.setText(this.getString(stringId));
    fieldName.setTextSize(16);
    fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(),
            fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom());
    fieldName.setOnClickListener(spinnerOpener);
    row.addView(fieldName);
    final TextView fieldValueLocal = new TextView(this);
    fieldValueLocal.setText(fieldLocal);
    fieldValueLocal.setTextSize(16);
    row.addView(fieldValueLocal);
    fieldValueLocal.setOnClickListener(spinnerOpener);

    fieldTable.addView(row);
    row = new TableRow(this);
    row.addView(new TextView(this));// add dummy control
    final TextView fieldValueRemote = new TextView(this);
    fieldValueRemote.setText(fieldRemote);
    fieldValueRemote.setTextSize(16);

    fieldValueRemote.setOnClickListener(spinnerOpener);
    row.addView(fieldValueRemote);
    sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldLocal);
            } else {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldRemote);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> view) {
        }
    });
    row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10);
    // Restore appropiate selections according to resolved contact
    if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) {
        sourceSelect.setSelection(0);
    } else {
        sourceSelect.setSelection(1);
    }
    fieldTable.addView(row);
}

From source file:org.ementasua.SwipeyTabFragment.java

private void buildList(LayoutInflater inflater, TableLayout tl, Menu menu, boolean what, Button lunch,
        Button dinner, ImageView ib) {
    View v = null;/*from   www  . ja  v  a  2 s  . c o  m*/
    boolean t = true;
    String tmp = "";
    final String shareMsg;

    if (!what) {
        lunch.setBackgroundResource(R.drawable.table_menu_title_select);
        dinner.setBackgroundResource(R.drawable.table_menu_title_deselect);
        lunch.setClickable(false);
        dinner.setClickable(true);
        tmp = "Almo?o:\n";
    } else {
        lunch.setBackgroundResource(R.drawable.table_menu_title_deselect);
        dinner.setBackgroundResource(R.drawable.table_menu_title_select);
        lunch.setClickable(true);
        dinner.setClickable(false);
        tmp = "Jantar:\n";
    }

    Animation animation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
    animation.setDuration(1000);

    tl.startAnimation(animation);
    tl.removeAllViews();

    if (!menu.isDisabled()) {
        for (Plate p : menu.getPlates()) {
            if (p.getName().length() > 0 && showPlate(p)) {
                v = buildRow(inflater, p);
                if (t)
                    v.setBackgroundResource(R.drawable.border1);
                else
                    v.setBackgroundResource(R.drawable.border2);
                t = !t;
                tl.addView(v);
            }
            if (p.getType().contains("Prato") && p.getName() != "" && p.getName().length() > 0) {
                tmp += p.getName() + "; ";
            }
        }
        ib.setVisibility(View.VISIBLE);
    } else {
        v = buildRow(inflater, new Plate("", menu.getDisabledText()));
        v.setBackgroundResource(R.drawable.border1);
        tl.addView(v);
        ib.setVisibility(View.GONE);
    }

    shareMsg = tmp;

    ib.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Ementas do " + getArguments().getString("title"));
            String shareMessage = getArguments().getString("title") + " - " + shareMsg;
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);
            startActivity(Intent.createChooser(shareIntent, "Partilhar para onde:"));
        }
    });
}

From source file:de.tobiasbielefeld.solitaire.ui.statistics.RecentScoresFragment.java

/**
 * Loads the high score list//from   w ww. j  a v a2s . c o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_statistics_tab3, 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.getRecentScore(0, 2) != 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.getRecentScore(i, 2) == 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.getRecentScore(i, 0), dollar));
        long time = scores.getRecentScore(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.getRecentScore(i, 2)));
        textView4.setText(
                new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.getRecentScore(i, 2)));

        tableLayout.addView(row);
    }

    return view;
}

From source file:com.bonsai.wallet32.SendBitcoinActivity.java

private void addAccountRow(TableLayout table, int acctId, String acctName, long btc, double fiat) {
    TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.send_from_row, table, false);

    RadioButton tv0 = (RadioButton) row.findViewById(R.id.from_account);
    tv0.setId(acctId); // Change id to the acctId.
    tv0.setText(acctName);/*from  w  w  w. j av  a2s  .  co  m*/
    tv0.setOnCheckedChangeListener(mSendFromListener);
    if (acctId == mCheckedFromId)
        tv0.setChecked(true);

    TextView tv1 = (TextView) row.findViewById(R.id.row_btc);
    tv1.setText(String.format("%s", mBTCFmt.formatCol(btc, 0, true, true)));

    TextView tv2 = (TextView) row.findViewById(R.id.row_fiat);
    tv2.setText(String.format("%.02f", fiat));

    table.addView(row);
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * VIN??//www  . jav a  2 s  .c o m
 */
private void checkVinAndGetCarSettings() {
    InputMethodManager imm = (InputMethodManager) rootView.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(findViewById(R.id.vin_edit).getWindowToken(), 0);

    final String vinString = getEditViewText(rootView, R.id.vin_edit);

    // ?
    if (vinString.equals("")) {
        Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
        findViewById(R.id.vin_edit).requestFocus();
        return;
    }

    // VIN?
    if (!isVin(vinString)) {
        View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null);
        TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
        TextView content = new TextView(view1.getContext());
        content.setText("VIN?: " + vinString + "\n"
                + "VIN?????\n");
        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) {
                        setEditViewText(rootView, R.id.brand_edit, "");
                        findViewById(R.id.brand_select_button).setEnabled(false);

                        // ???VIN
                        getCarSettingsFromServer();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        findViewById(R.id.vin_edit).requestFocus();
                    }
                }).create();

        dialog.show();
        return;
    }

    setEditViewText(rootView, R.id.brand_edit, "");
    findViewById(R.id.brand_select_button).setEnabled(false);

    // ???VIN
    getCarSettingsFromServer();
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * ??? (vin)//from  w  w  w. jav  a 2 s.  c o m
 */
private void getCarSettingsFromServer() {
    String vin = getEditViewText(rootView, R.id.vin_edit);

    GetCarSettingsByVinTask getCarSettingsByVinTask = new GetCarSettingsByVinTask(getContext(), vin,
            new GetCarSettingsByVinTask.OnGetCarSettingsFinished() {
                @Override
                public void onFinished(String result) {
                    final List<String> modelNames;
                    final List<JSONObject> jsonObjects;

                    try {
                        JSONArray jsonArray = new JSONArray(result);
                        jsonObjects = new ArrayList<JSONObject>();

                        // ??string list
                        modelNames = new ArrayList<String>();

                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);

                            Country country;
                            Brand brand;
                            Manufacturer manufacturer;
                            Series series;
                            Model model;

                            // ?ID?
                            if (jsonObject.has("countryId"))
                                country = vehicleModel.getCountryById(jsonObject.getString("countryId"));
                            else
                                country = vehicleModel.countries.get(0);

                            if (jsonObject.has("brandId"))
                                brand = country.getBrandById(jsonObject.getString("brandId"));
                            else
                                brand = country.brands.get(0);

                            if (jsonObject.has("manufacturerId"))
                                manufacturer = brand
                                        .getManufacturerById(jsonObject.getString("manufacturerId"));
                            else
                                manufacturer = brand.manufacturers.get(0);

                            if (jsonObject.has("seriesId"))
                                series = manufacturer.getSeriesById(jsonObject.getString("seriesId"));
                            else
                                series = manufacturer.serieses.get(0);

                            if (jsonObject.has("modelId"))
                                model = series.getModelById(jsonObject.getString("modelId"));
                            else
                                model = series.models.get(0);

                            // ??list??
                            jsonObjects.add(jsonObject);
                            modelNames.add(manufacturer.name + " " + series.name + " " + model.name);
                        }

                        String[] tempArray = new String[modelNames.size() + 1];

                        for (int i = 0; i < modelNames.size(); i++) {
                            tempArray[i] = modelNames.get(i);
                        }

                        showModelChooseDialog(tempArray, new OnChooseModelFinished() {
                            @Override
                            public void onFinished(int index) throws JSONException {
                                // ?????
                                if (index == modelNames.size()) {
                                    selectCarManually();
                                }
                                // ?
                                else {
                                    JSONObject jsonObject = jsonObjects.get(index);

                                    Country country = vehicleModel
                                            .getCountryById(jsonObject.getString("countryId"));
                                    Brand brand = country.getBrandById(jsonObject.getString("brandId"));
                                    Manufacturer manufacturer = brand
                                            .getManufacturerById(jsonObject.getString("manufacturerId"));
                                    Series series = manufacturer
                                            .getSeriesById(jsonObject.getString("seriesId"));
                                    Model model = series.getModelById(jsonObject.getString("modelId"));

                                    // ?idspinner?
                                    lastCountryIndex = vehicleModel.getCountryNames().indexOf(country.name);
                                    lastBrandIndex = country.getBrandNames().indexOf(brand.name);
                                    lastManufacturerIndex = brand.getManufacturerNames()
                                            .indexOf(manufacturer.name);
                                    lastSeriesIndex = manufacturer.getSeriesNames().indexOf(series.name);
                                    lastModelIndex = series.getModelNames().indexOf(model.name);

                                    // ??
                                    updateCarSettings();

                                    // UI
                                    updateUi();
                                }
                            }
                        });
                    } catch (JSONException e) {
                        Log.d("DFCarChecker", "Json?" + e.getMessage());
                    }
                }

                @Override
                public void onFailed(String result) {
                    // ??
                    Log.d("DFCarChecker", "???" + result);

                    if (result.equals("VIN??")) {
                        View view1 = ((Activity) getContext()).getLayoutInflater()
                                .inflate(R.layout.popup_layout, null);
                        TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
                        TextView content = new TextView(view1.getContext());
                        content.setText("?");
                        content.setTextSize(20f);
                        contentArea.addView(content);

                        setTextView(view1, R.id.title, getResources().getString(R.string.alert));

                        AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1)
                                .setPositiveButton(R.string.ok, null)
                                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        // ?
                                        selectCarManually();
                                        showView(rootView, R.id.brand_input, true);
                                    }
                                }).create();

                        dialog.show();

                        // ??
                        updateUi();
                    } else {
                        // ??
                        Log.d("DFCarChecker", "???" + result);
                        Toast.makeText(getContext(), result, Toast.LENGTH_LONG).show();
                    }
                }
            });
    getCarSettingsByVinTask.execute();
}

From source file:de.damdi.fitness.activity.start_training.DialogFragmentTrainingEntryTable.java

@SuppressLint("SimpleDateFormat")
@Override/*from  w  w w  . ja  v  a 2 s  .com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.dialog_training_entry_table, null);

    TableLayout table = (TableLayout) v.findViewById(R.id.table_training_entry);
    DateFormat dateformat = new SimpleDateFormat("dd.MM");
    boolean odd = false;

    Iterator<TrainingEntry> it = mFex.getTrainingEntryList().iterator();
    int entry_count = 0;

    while (it.hasNext()) {
        TrainingEntry entry = it.next();

        for (FSet set : entry.getFSetList()) {
            TableRow row;
            if (odd) {
                row = (TableRow) inflater.inflate(R.layout.row_type_1, null);
            } else {
                row = (TableRow) inflater.inflate(R.layout.row_type_2, null);
            }
            odd = !odd;

            TextView text_view_date = (TextView) row.findViewById(R.id.text_view_date);
            text_view_date.setText(dateformat.format(entry.getDate()));

            for (SetParameter parameter : set.getSetParameters()) {
                TextView text_view_duration = (TextView) row.findViewById(R.id.text_view_duration);
                TextView text_view_rep = (TextView) row.findViewById(R.id.text_view_rep);
                TextView text_view_weigh = (TextView) row.findViewById(R.id.text_view_weigh);

                if (parameter instanceof SetParameter.Duration) {
                    text_view_duration.setText(parameter.toString());
                }

                if (parameter instanceof SetParameter.Repetition) {
                    text_view_rep.setText(parameter.toString());
                }

                if (parameter instanceof SetParameter.Weight) {
                    text_view_weigh.setText(parameter.toString());
                }
            }

            entry_count++;

            table.addView(row);
        }

        // only append diver row(=just a black row) if there are more rows
        if (it.hasNext()) {
            TableRow row_empty = (TableRow) inflater.inflate(R.layout.row_type_empty_row, null);
            table.addView(row_empty);
        }
    }

    if (entry_count == 0) {
        return new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.no_other_training_entries))
                .setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setCancelable(true).create();
    }

    return new AlertDialog.Builder(getActivity()).setView(v).setCancelable(false).create();
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * // w  w  w  .ja  v  a  2  s .  co  m
 * @param arrayId
 * @param editViewId
 */
private void choose(final int arrayId, final int editViewId) {
    View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null);

    final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create();

    TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);

    final ListView listView = new ListView(view1.getContext());

    listView.setAdapter(new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1,
            view1.getResources().getStringArray(arrayId)));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            dialog.dismiss();
            String temp = (String) listView.getItemAtPosition(i);
            setEditViewText(rootView, editViewId, temp);
        }
    });

    contentArea.addView(listView);

    setTextView(view1, R.id.title, getResources().getString(R.string.alert));

    dialog.show();
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * ?/*from ww w. ja  va2 s.  c  om*/
 * @param array
 * @param mCallback
 * @throws JSONException
 */
private void showModelChooseDialog(String[] array, final OnChooseModelFinished mCallback) throws JSONException {
    array[array.length - 1] = "";

    View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null);

    final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create();

    TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
    final ListView listView = new ListView(view1.getContext());
    listView.setAdapter(
            new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1, array));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            try {
                mCallback.onFinished(i);
                dialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    contentArea.addView(listView);

    setTextView(view1, R.id.title, getResources().getString(R.string.select_model));

    dialog.show();
}