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.sim2dial.dialer.ContactFragment.java

private void displayContact(LayoutInflater inflater, View view) {
    AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    if (contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(
                LinphoneActivity.instance().getContentResolver(), contact.getID());
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {//from w w  w. j av  a2 s.  c o m
        contactPicture.setImageResource(R.drawable.unknown_small);
    }

    TextView contactName = (TextView) view.findViewById(R.id.contactName);
    contactName.setText(contact.getName());

    TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
    controls.removeAllViews();
    for (String numberOrAddress : contact.getNumerosOrAddresses()) {
        View v = inflater.inflate(R.layout.contact_control_row, null);

        String displayednumberOrAddress = numberOrAddress;
        if (numberOrAddress.startsWith("sip:")) {
            displayednumberOrAddress = displayednumberOrAddress.substring(4);
        }

        TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
        tv.setText(displayednumberOrAddress);
        tv.setSelected(true);

        if (!displayChatAddressOnly) {
            v.findViewById(R.id.dial).setOnClickListener(dialListener);
            v.findViewById(R.id.dial).setTag(displayednumberOrAddress);
        } else {
            v.findViewById(R.id.dial).setVisibility(View.GONE);
        }

        v.findViewById(R.id.chat).setOnClickListener(chatListener);
        if (LinphoneUtils.isSipAddress(numberOrAddress)) {
            v.findViewById(R.id.chat).setTag(numberOrAddress);
        } else {
            LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
            if (lpc != null) {
                if (!numberOrAddress.startsWith("sip:")) {
                    numberOrAddress = "sip:" + numberOrAddress;
                }
                v.findViewById(R.id.chat).setTag(numberOrAddress + "@" + lpc.getDomain());
            }
        }

        final String finalNumberOrAddress = numberOrAddress;
        ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
        if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
            friend.setVisibility(View.VISIBLE);

            boolean isAlreadyAFriend = LinphoneManager.getLc()
                    .findFriendByAddress(finalNumberOrAddress) != null;
            if (!isAlreadyAFriend) {
                friend.setImageResource(R.drawable.friend_add);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            } else {
                friend.setImageResource(R.drawable.friend_remove);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            }
        }

        if (getResources().getBoolean(R.bool.disable_chat)) {
            v.findViewById(R.id.chat).setVisibility(View.GONE);
        }

        controls.addView(v);
    }
}

From source file:eu.power_switch.gui.adapter.RoomRecyclerViewAdapter.java

private void updateReceiverViews(final RoomRecyclerViewAdapter.ViewHolder holder, final Room room) {
    String inflaterString = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater inflater = (LayoutInflater) fragmentActivity.getSystemService(inflaterString);

    // clear previous items
    holder.linearLayoutOfReceivers.removeAllViews();
    // add items// ww w  .j a  v  a 2  s .co  m
    for (final Receiver receiver : room.getReceivers()) {
        // create a new receiverRow for our current receiver and add it to
        // our table of all devices of our current room
        // the row will contain the device name and all buttons

        LinearLayout receiverLayout = (LinearLayout) inflater.inflate(R.layout.list_item_receiver,
                holder.linearLayoutOfReceivers, false);
        receiverLayout.setOrientation(LinearLayout.HORIZONTAL);
        holder.linearLayoutOfReceivers.addView(receiverLayout);

        // setup TextView to display device name
        TextView receiverName = (TextView) receiverLayout.findViewById(R.id.txt_name);
        receiverName.setText(receiver.getName());
        receiverName.setTextSize(18);

        TableLayout buttonLayout = (TableLayout) receiverLayout.findViewById(R.id.buttonLayout);
        int buttonsPerRow;
        if (receiver.getButtons().size() % 3 == 0) {
            buttonsPerRow = 3;
        } else {
            buttonsPerRow = 2;
        }

        int i = 0;
        final ArrayList<android.widget.Button> buttonViews = new ArrayList<>();
        long lastActivatedButtonId = receiver.getLastActivatedButtonId();
        TableRow buttonRow = null;
        for (final Button button : receiver.getButtons()) {
            final android.widget.Button buttonView = (android.widget.Button) inflater
                    .inflate(R.layout.simple_button, buttonRow, false);
            final ColorStateList defaultTextColor = buttonView.getTextColors(); //save original colors
            buttonViews.add(buttonView);
            buttonView.setText(button.getName());
            final int accentColor = ThemeHelper.getThemeAttrColor(fragmentActivity, R.attr.colorAccent);
            if (SmartphonePreferencesHandler.getHighlightLastActivatedButton() && lastActivatedButtonId != -1
                    && button.getId() == lastActivatedButtonId) {
                buttonView.setTextColor(accentColor);
            }
            buttonView.setOnClickListener(new android.widget.Button.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    if (SmartphonePreferencesHandler.getVibrateOnButtonPress()) {
                        VibrationHandler.vibrate(fragmentActivity,
                                SmartphonePreferencesHandler.getVibrationDuration());
                    }

                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            // send signal
                            ActionHandler.execute(fragmentActivity, receiver, button);
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void aVoid) {
                            if (SmartphonePreferencesHandler.getHighlightLastActivatedButton()) {
                                for (android.widget.Button button : buttonViews) {
                                    if (button != v) {
                                        button.setTextColor(defaultTextColor);
                                    } else {
                                        button.setTextColor(accentColor);
                                    }
                                }
                            }
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });

            if (i == 0 || i % buttonsPerRow == 0) {
                buttonRow = new TableRow(fragmentActivity);
                buttonRow.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.MATCH_PARENT));
                buttonRow.addView(buttonView);
                buttonLayout.addView(buttonRow);
            } else {
                buttonRow.addView(buttonView);
            }

            i++;
        }

        receiverLayout.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                ConfigureReceiverDialog configureReceiverDialog = ConfigureReceiverDialog
                        .newInstance(receiver.getId());
                configureReceiverDialog.setTargetFragment(recyclerViewFragment, 0);
                configureReceiverDialog.show(fragmentActivity.getSupportFragmentManager(), null);
                return true;
            }
        });
    }
}

From source file:org.xingjitong.ContactFragment.java

private void displayContact(LayoutInflater inflater, View view) {
    AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    if (contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(),
                contact.getID());/*from  w  w  w  .  jav a  2s.  c o  m*/
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
        contactPicture.setImageResource(R.drawable.unknown_small);
    }

    TextView contactName = (TextView) view.findViewById(R.id.contactName);
    contactName.setText(contact.getName());
    contactName.setTextColor(Color.BLACK);
    View view2 = inflater.inflate(R.layout.edit_contact, null);
    TableLayout controls = (TableLayout) view2.findViewById(R.id.controls);
    if (controls.getChildCount() > 0 && controls != null) {
        controls.removeAllViews();
    }
    for (String numberOrAddress : contact.getNumerosOrAddresses()) {
        //yyppdialog
        View v = inflater.inflate(R.layout.contact_control_row, null);

        String displayednumberOrAddress = numberOrAddress;
        if (numberOrAddress.startsWith("sip:")) {
            displayednumberOrAddress = displayednumberOrAddress.substring(4);
        }

        TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
        tv.setText(displayednumberOrAddress);
        tv.setSelected(true);

        if (!displayChatAddressOnly) {
            //yyppcontact //yyppdialog
            v.findViewById(R.id.dial).setOnClickListener(dialListener);
            v.findViewById(R.id.dial).setTag(displayednumberOrAddress);
        } else {

            v.findViewById(R.id.dial).setVisibility(View.GONE);
        }

        v.findViewById(R.id.chat).setOnClickListener(chatListener);
        if (LinphoneUtils.isSipAddress(numberOrAddress)) {
            v.findViewById(R.id.chat).setTag(numberOrAddress);
        } else {
            LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
            if (lpc != null) {
                if (!numberOrAddress.startsWith("sip:")) {
                    numberOrAddress = "sip:" + numberOrAddress;
                }
                v.findViewById(R.id.chat).setTag(numberOrAddress + "@" + lpc.getDomain());
            }
        }

        final String finalNumberOrAddress = numberOrAddress;
        ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
        if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
            friend.setVisibility(View.VISIBLE);

            boolean isAlreadyAFriend = LinphoneManager.getLc()
                    .findFriendByAddress(finalNumberOrAddress) != null;
            if (!isAlreadyAFriend) {
                friend.setImageResource(R.drawable.friend_add);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            } else {
                friend.setImageResource(R.drawable.friend_remove);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            }
        }

        if (getResources().getBoolean(R.bool.disable_chat)) {
            v.findViewById(R.id.chat).setVisibility(View.GONE);
        }

        controls.addView(v);
    }
}

From source file:org.linphone.ContactFragment.java

@SuppressLint("InflateParams")
private void displayContact(LayoutInflater inflater, View view) {
    AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    if (contact.getPhotoUri() != null) {
        InputStream input = Compatibility.getContactPictureInputStream(
                LinphoneActivity.instance().getContentResolver(), contact.getID());
        contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {//from   www .j av a 2  s .  c o m
        contactPicture.setImageResource(R.drawable.unknown_small);
    }

    TextView contactName = (TextView) view.findViewById(R.id.contactName);
    contactName.setText(contact.getName());

    TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
    controls.removeAllViews();
    for (String numberOrAddress : contact.getNumbersOrAddresses()) {
        View v = inflater.inflate(R.layout.contact_control_row, null);

        String displayednumberOrAddress = numberOrAddress;
        if (numberOrAddress.startsWith("sip:")) {
            displayednumberOrAddress = displayednumberOrAddress.replace("sip:", "");
        }

        TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
        tv.setText(displayednumberOrAddress);
        tv.setSelected(true);

        if (!displayChatAddressOnly) {
            v.findViewById(R.id.dial).setOnClickListener(dialListener);
            v.findViewById(R.id.dial).setTag(displayednumberOrAddress);
        } else {
            v.findViewById(R.id.dial).setVisibility(View.GONE);
        }

        v.findViewById(R.id.start_chat).setOnClickListener(chatListener);
        LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
        if (lpc != null) {
            displayednumberOrAddress = lpc.normalizePhoneNumber(displayednumberOrAddress);
            if (!displayednumberOrAddress.startsWith("sip:")) {
                numberOrAddress = "sip:" + displayednumberOrAddress;
            }

            String tag = numberOrAddress;
            if (!numberOrAddress.contains("@")) {
                tag = numberOrAddress + "@" + lpc.getDomain();
            }
            v.findViewById(R.id.start_chat).setTag(tag);
        } else {
            v.findViewById(R.id.start_chat).setTag(numberOrAddress);
        }

        final String finalNumberOrAddress = numberOrAddress;
        ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
        if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
            friend.setVisibility(View.VISIBLE);

            boolean isAlreadyAFriend = LinphoneManager.getLc()
                    .findFriendByAddress(finalNumberOrAddress) != null;
            if (!isAlreadyAFriend) {
                friend.setImageResource(R.drawable.friend_add);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (ContactsManager.getInstance().createNewFriend(contact, finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            } else {
                friend.setImageResource(R.drawable.friend_remove);
                friend.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (ContactsManager.getInstance().removeFriend(finalNumberOrAddress)) {
                            displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
                        }
                    }
                });
            }
        }

        if (getResources().getBoolean(R.bool.disable_chat)) {
            v.findViewById(R.id.start_chat).setVisibility(View.GONE);
        }

        controls.addView(v);
    }
}

From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java

/**
 * Add a row to the provided TableLayout. The row contains an EditText for the field name with a
 * delete button. The delete button becomes an undo button if the provided listener allows undo.
 * If undo is not allowed, the delete button will remove the row.
 *
 * @param tableLayout The TableLayout to add a row to
 * @param text        The text to fill the text field
 * @param maxLength   The maximum allowed length of the text field
 * @param hint        The hint for the EditText
 * @param deleteHint  The contentDescription for the delete Button
 * @param deleted     The initial deleted status of the field
 * @param listener    The event listener for the field
 *//*from   w w  w  .  j  av  a2  s .  c o m*/
private void addTableRow(@NonNull final TableLayout tableLayout, @Nullable String text, int maxLength, int hint,
        final int deleteHint, final boolean deleted, @NonNull final CatFieldListener listener) {
    final LayoutInflater inflater = LayoutInflater.from(getContext());
    final View root = inflater.inflate(R.layout.edit_cat_field, tableLayout, false);

    final InputFilter[] filters = new InputFilter[] { new InputFilter.LengthFilter(maxLength) };
    final EditText editText = root.findViewById(R.id.field_name);
    editText.setFilters(filters);
    editText.setHint(hint);
    editText.setText(text);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            listener.onNameChange(s.toString());
        }
    });

    final ImageButton deleteButton = root.findViewById(R.id.button_delete);
    deleteButton.setContentDescription(getString(deleteHint));
    deleteButton.setOnClickListener(new View.OnClickListener() {
        private boolean mDeleted = deleted;

        @Override
        public void onClick(View v) {
            if (mDeleted) {
                setDeleted(false);
                listener.onUndoDelete();
            } else {
                if (!listener.allowUndo()) {
                    tableLayout.removeView(root);
                } else {
                    setDeleted(true);
                }
                listener.onDelete();
            }
        }

        private void setDeleted(boolean deleted) {
            mDeleted = deleted;
            editText.setEnabled(!deleted);
            if (deleted) {
                deleteButton.setImageResource(R.drawable.ic_undo);
                deleteButton.setContentDescription(getString(R.string.button_undo));
                editText.setPaintFlags(editText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            } else {
                deleteButton.setImageResource(R.drawable.ic_clear);
                deleteButton.setContentDescription(getString(deleteHint));
                editText.setPaintFlags(editText.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
            }
        }
    });

    if (deleted) {
        editText.setEnabled(false);
        deleteButton.setImageResource(R.drawable.ic_undo);
        deleteButton.setContentDescription(getString(R.string.button_undo));
        editText.setPaintFlags(editText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    }

    tableLayout.addView(root);
    if (TextUtils.isEmpty(text)) {
        editText.requestFocus();
    }
}

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

/** Presents additional information about a specific assistant.
 * @return a dynamically generated linear layout
 *///from w  w  w.ja va  2s  . c  o m
private LinearLayout getServiceDescLayout() {
    final LinearLayout output = new LinearLayout(this);
    final RelativeLayout topButtonsLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    final Button btnBack = new Button(this);
    btnBack.setText(R.string.btnAllServices);
    btnBack.setId(5);
    btnBack.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            output.setVisibility(View.GONE);
            getListView().setVisibility(View.VISIBLE);
            lblAvAssist.setVisibility(View.VISIBLE);
        }
    });

    topButtonsLayout.addView(btnBack);

    final Button btnInvoke = new Button(this);
    btnInvoke.setText(R.string.btnInvokeLabel);
    btnInvoke.setId(6);

    btnInvoke.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new InvocationTask().execute();
        }
    });

    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, btnInvoke.getId());
    btnInvoke.setLayoutParams(layoutParams);
    topButtonsLayout.addView(btnInvoke);

    output.addView(topButtonsLayout);

    TableLayout serviceInfoTbl = new TableLayout(this);
    output.addView(serviceInfoTbl);

    serviceInfoTbl.setColumnShrinkable(1, true);

    /* FIRST ROW */
    TableRow rowServiceName = new TableRow(this);

    TextView lblServiceName = new TextView(this);
    lblServiceName.setText(R.string.lblServiceName);
    lblServiceName.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceName = new TextView(this);
    txtServiceName.setText(selectedService);
    txtServiceName.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceName.setPadding(10, 0, 0, 0);

    rowServiceName.addView(lblServiceName);
    rowServiceName.addView(txtServiceName);

    /* SECOND ROW */
    TableRow rowServiceDesc = new TableRow(this);

    TextView lblServiceDesc = new TextView(this);
    lblServiceDesc.setText(R.string.lblServiceDesc);
    lblServiceDesc.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceDesc = new TextView(this);
    txtServiceDesc.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceDesc.setPadding(10, 0, 0, 0);
    List<GateRuntimeParameter> params = null;
    ServiceInfoForClientArray list = getServices();
    for (int i = 0; i < list.getItem().size(); i++) {
        if (list.getItem().get(i).getServiceName().equals(selectedService)) {
            txtServiceDesc.setText(list.getItem().get(i).getServiceDescription());
            params = list.getItem().get(i).getParams();
            break;
        }
    }

    TextView lblParams = new TextView(this);
    lblParams.setText(R.string.lblServiceParams);
    lblParams.setTextAppearance(getApplicationContext(), R.style.titleText);
    output.addView(lblParams);

    LayoutParams txtParamsAttrbs = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    LinearLayout paramsLayout = new LinearLayout(this);
    paramsLayout.setId(0);

    if (params.size() > 0) {
        ScrollView scroll = new ScrollView(this);
        scroll.setLayoutParams(txtParamsAttrbs);
        paramsLayout.setOrientation(LinearLayout.VERTICAL);
        scroll.addView(paramsLayout);
        for (int j = 0; j < params.size(); j++) {
            TextView lblParamName = new TextView(this);
            lblParamName.setText(params.get(j).getParamName());
            EditText tview = new EditText(this);
            tview.setId(1);
            tview.setText(params.get(j).getDefaultValueString());
            LayoutParams txtViewLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT);
            tview.setLayoutParams(txtViewLayoutParams);
            paramsLayout.addView(lblParamName);
            paramsLayout.addView(tview);
        }
        output.addView(scroll);
    } else {
        TextView lblParamName = new TextView(this);
        lblParamName.setText(R.string.lblRTParams);
        output.addView(lblParamName);
    }

    rowServiceDesc.addView(lblServiceDesc);
    rowServiceDesc.addView(txtServiceDesc);

    serviceInfoTbl.addView(rowServiceName);
    serviceInfoTbl.addView(rowServiceDesc);

    output.setOrientation(LinearLayout.VERTICAL);
    output.setGravity(Gravity.TOP);

    return output;
}

From source file:com.example.diplimadoapp.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*  www  . j a va2 s  . co  m*/

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    switch (position) {
    case 0:

        LinearLayout ll = new LinearLayout(getActivity());
        ll.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);

        ImageView iv = new ImageView(getActivity());
        iv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1020));
        //iv.setLayoutParams(new  LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        iv.setMaxHeight(520);
        iv.setImageResource(R.drawable.contact);
        ll.addView(iv);

        TableLayout tl = new TableLayout(getActivity());
        tl.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr = new TableRow(getActivity());
        tr.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr.setGravity(Gravity.FILL_HORIZONTAL);
        tr.setPadding(5, 5, 5, 5);

        List<RssItem> lecturaitems = null;
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            lecturaitems = rssReader.getItems();

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }

        TextView v1 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v1.setGravity(Gravity.CENTER);
        v1.setBackgroundResource(R.drawable.background_card);
        if (lecturaitems != null) {
            v1.setText(lecturaitems.get(0).getTitle());
            String urlnoticia = lecturaitems.get(0).getLink();
            v1.setOnClickListener(new NoticiaDestacadaOnClickListener(urlnoticia));
        } else {
            v1.setText("No Registra nuevas noticias");
        }

        tr.addView(v1);

        ImageButton ib = new ImageButton(getActivity());
        ib.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib.setImageResource(R.drawable.facebook);

        ib.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.facebook.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib);

        ImageButton ib2 = new ImageButton(getActivity());
        ib2.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib2.setImageResource(R.drawable.twitter);

        ib2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.twitter.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib2);

        ImageButton ib3 = new ImageButton(getActivity());
        ib3.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib3.setImageResource(R.drawable.youtube);

        ib3.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.youtube.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib3);

        tl.addView(tr);

        ll.addView(tl);

        fl.addView(ll);

        break;

    case 1:

        LinearLayout ll2 = new LinearLayout(getActivity());
        ll2.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll2.setOrientation(LinearLayout.VERTICAL);

        TableLayout tl2 = new TableLayout(getActivity());
        tl2.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr2 = new TableRow(getActivity());
        tr2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr2.setGravity(Gravity.FILL_HORIZONTAL);
        tr2.setPadding(5, 5, 5, 5);

        TextView v0 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v0.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v0.setGravity(Gravity.CENTER);
        v0.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr2.addView(v0);

        ImageButton ib20 = new ImageButton(getActivity());
        ib20.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib20.setImageResource(R.drawable.pacusticos);
        ib20.setBackgroundDrawable(null);

        tr2.addView(ib20);

        tl2.addView(tr2);

        TableRow tr3 = new TableRow(getActivity());
        tr3.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr3.setGravity(Gravity.FILL_HORIZONTAL);
        tr3.setPadding(5, 5, 5, 5);

        TextView v03 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v03.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v03.setGravity(Gravity.CENTER);
        v03.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr3.addView(v03);

        ImageButton ib30 = new ImageButton(getActivity());
        ib30.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib30.setImageResource(R.drawable.pradionica_lacarta);
        ib30.setBackgroundDrawable(null);

        tr3.addView(ib30);

        tl2.addView(tr3);

        TableRow tr4 = new TableRow(getActivity());
        tr4.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr4.setGravity(Gravity.FILL_HORIZONTAL);
        tr4.setPadding(5, 5, 5, 5);

        TextView v04 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v04.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v04.setGravity(Gravity.CENTER);
        v04.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr4.addView(v04);

        tl2.addView(tr4);

        ImageButton ib40 = new ImageButton(getActivity());
        ib40.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib40.setImageResource(R.drawable.prockeros);
        ib40.setBackgroundDrawable(null);

        tr4.addView(ib40);

        ll2.addView(tl2);

        /*
        VideoView videoView = new VideoView(getActivity());
                
        Uri path = Uri.parse("rtmp://cdns840stu0010.multistream.net:80/rtvcRadionicalive/?pass=|radionica|");
                
        videoView.setVideoURI(path);
        videoView.start(); 
                
        TableRow tr5 =new TableRow(getActivity());
        tr5.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        tr5.setGravity(Gravity.FILL_HORIZONTAL);
        tr5.setPadding(5,5,5,5);
        tr5.addView(videoView);
                
        ll2.addView(tr5);*/

        fl.addView(ll2);
        break;
    case 2:
        ListView lv = new ListView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        lv.setLayoutParams(params);
        lv.setLayoutParams(params);
        lv.setBackgroundResource(R.drawable.background_card);
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            List<RssItem> lecturaitems2 = rssReader.getItems();
            // Create a list adapter
            ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),
                    android.R.layout.simple_list_item_1, lecturaitems2);
            // Set list adapter for the ListView
            lv.setAdapter(adapter);

            // Set list view item click listener
            lv.setOnItemClickListener(new ListListener(lecturaitems2, getActivity()));

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }
        fl.addView(lv);
        break;
    }

    return fl;
}

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

private void addPeopleSession(Member membre) {
    //On recupere aussi la liste des sessions de l'utilisateur
    List<Talk> conferences = ConferenceFacade.getInstance().getSessionMembre(membre, getActivity());

    //On vide les lments
    sessionLayout.removeAllViews();/*from www .  j av a 2s  .c o  m*/

    //On affiche les liens que si on a recuperer des choses
    if (conferences != null && !conferences.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) {

            for (final Talk conf : conferences) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_talk, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView horaire = (TextView) row.findViewById(R.id.talk_horaire);
                TextView talkImageText = (TextView) row.findViewById(R.id.talkImageText);
                TextView talkSalle = (TextView) row.findViewById(R.id.talk_salle);
                ImageView imageFavorite = (ImageView) row.findViewById(R.id.talk_image_favorite);
                ImageView langImage = (ImageView) row.findViewById(R.id.talk_image_language);

                ((TextView) row.findViewById(R.id.talk_name)).setText(conf.getTitle());
                ((TextView) row.findViewById(R.id.talk_shortdesciptif)).setText(conf.getSummary().trim());

                SimpleDateFormat sdf = new SimpleDateFormat("EEE");
                if (conf.getStart() != null && conf.getEnd() != null) {
                    horaire.setText(String.format(getResources().getString(R.string.periode),
                            sdf.format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getEnd())));
                } else {
                    horaire.setText(getResources().getString(R.string.pasdate));

                }
                if (conf.getLang() != null && "ENGLISH".equals(conf.getLang())) {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.en));
                } else {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.fr));
                }
                Salle salle = Salle.INCONNU;
                if (conf instanceof Talk && Salle.INCONNU != Salle.getSalle(conf.getRoom())) {
                    salle = Salle.getSalle(conf.getRoom());
                }
                talkSalle.setText(String.format(getResources().getString(R.string.Salle), salle.getNom()));
                talkSalle.setBackgroundColor(getResources().getColor(salle.getColor()));

                if (conf instanceof Talk) {
                    if ("Workshop".equals(((Talk) conf).getFormat())) {
                        talkImageText.setText("Atelier");
                    } else {
                        talkImageText.setText("Talk");
                    }
                } else {
                    talkImageText.setText("L.Talk");
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TypeFile typeFile;
                        int page = 6;
                        if (conf instanceof Talk) {
                            if ("Workshop".equals(((Talk) conf).getFormat())) {
                                typeFile = TypeFile.workshops;
                                page = 4;
                            } else {
                                typeFile = TypeFile.talks;
                                page = 3;
                            }
                        } else {
                            typeFile = TypeFile.lightningtalks;
                        }
                        ((HomeActivity) getActivity()).changeCurrentFragment(SessionDetailFragment.newInstance(
                                typeFile.toString(), conf.getIdSession(), page), typeFile.toString());
                    }
                });

                //On regarde si la conf fait partie des favoris
                SharedPreferences settings = getActivity().getSharedPreferences(UIUtils.PREFS_FAVORITES_NAME,
                        0);
                boolean trouve = false;
                for (String key : settings.getAll().keySet()) {
                    if (key.equals(String.valueOf(conf.getIdSession()))) {
                        trouve = true;
                        imageFavorite.setImageDrawable(
                                getActivity().getResources().getDrawable(R.drawable.ic_action_important));
                        break;
                    }
                }
                if (!trouve) {
                    imageFavorite.setImageDrawable(
                            getActivity().getResources().getDrawable(R.drawable.ic_action_not_important));
                }
                tableLayout.addView(row);
            }
        }
        sessionLayout.addView(tableLayout);
    } else {
        titleSessions.getLayoutParams().height = 0;
    }
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

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

    Bundle parameters = this.getIntent().getExtras();
    if (parameters != null) {
        TextView textViewDrug = (TextView) findViewById(R.id.textView_drug_name);
        textViewDrug.setTypeface(Typeface.SANS_SERIF);
        textViewDrug.setText(parameters.getString("drugName"));
        TextView textViewGroupName = (TextView) findViewById(R.id.textView_group_name);
        textViewGroupName.setTypeface(Typeface.SANS_SERIF);
        textViewGroupName.setText("(" + parameters.getString("groupName") + ")");
        layoutDose = (LinearLayout) findViewById(R.id.layout_dose);

        helper = new Handler_Sqlite(this);
        SQLiteDatabase db = helper.open();
        ArrayList<String> notes_index = new ArrayList<String>();
        ArrayList<String> references = new ArrayList<String>();
        ArrayList<Article_Reference> references_index = new ArrayList<Article_Reference>();
        reference_index = 'a';
        ArrayList<String> families = new ArrayList<String>();
        if (db != null)
            families = helper.read_animals_family(parameters.getString("drugName"),
                    parameters.getString("groupName"));

        for (int l = 0; l < families.size(); l++) {
            //if exists animals family

            TextView textView_family = new TextView(this);
            textView_family.setText(families.get(l));
            textView_family.setTextSize(20);
            textView_family.setTextColor(getResources().getColor(R.color.darkGray));
            textView_family.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            params.leftMargin = 30;/*from  ww  w .j  a v  a 2  s .  c om*/
            params.topMargin = 20;
            layoutDose.addView(textView_family, layoutDose.getChildCount(), params);

            //dose information

            LinearLayout layout_dose_information = new LinearLayout(this);
            layout_dose_information.setOrientation(LinearLayout.VERTICAL);
            layout_dose_information
                    .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            layout_dose_information.setBackgroundResource(R.drawable.layout_border);

            ArrayList<Dose_Data> dose = new ArrayList<Dose_Data>();
            if (db != null) {
                dose = helper.read_dose_information(parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l), "", "");
            }
            TableLayout doseTable = new TableLayout(this);
            doseTable.setStretchAllColumns(true);

            screenWidth = Integer.parseInt(getString(R.string.display));

            TableRow header = new TableRow(this);

            //Amount

            TextView textView_dose_amount = new TextView(this);
            textView_dose_amount.setText("Dose");
            textView_dose_amount.setSingleLine(true);
            textView_dose_amount.setTextColor(getResources().getColor(R.color.darkGray));
            textView_dose_amount.setTextSize(17);
            textView_dose_amount.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsAmount = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsAmount.gravity = Gravity.CENTER;
            header.addView(textView_dose_amount, paramsAmount);

            //Posology
            TextView textView_posology = new TextView(this);
            if (screenWidth >= 720)
                textView_posology.setText("Posology");
            else
                textView_posology.setText("Pos");
            textView_posology.setSingleLine(true);
            textView_posology.setTextColor(getResources().getColor(R.color.darkGray));
            textView_posology.setTextSize(17);
            textView_posology.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsPosology = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsPosology.gravity = Gravity.CENTER;
            if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"),
                    parameters.getString("groupName"), families.get(l), "Posology")) || screenWidth >= 600)
                header.addView(textView_posology, paramsPosology);

            //Route

            TextView textView_route = new TextView(this);
            textView_route.setText("Route");
            textView_route.setSingleLine(true);
            textView_route.setTextColor(getResources().getColor(R.color.darkGray));
            textView_route.setTextSize(17);
            textView_route.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsRoute = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
            paramsRoute.gravity = Gravity.CENTER;
            header.addView(textView_route, paramsRoute);

            //Reference

            TextView textView_reference = new TextView(this);
            textView_reference.setText("Ref");
            textView_reference.setSingleLine(true);
            textView_reference.setTextColor(getResources().getColor(R.color.darkGray));
            textView_reference.setTextSize(17);
            textView_reference.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsReference = new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
            paramsReference.gravity = Gravity.CENTER;
            header.addView(textView_reference, paramsReference);

            //Specific Note

            TextView textView_specific_note = new TextView(this);
            textView_specific_note.setText("Note");
            textView_specific_note.setSingleLine(true);
            textView_specific_note.setTextColor(getResources().getColor(R.color.darkGray));
            textView_specific_note.setTextSize(17);
            textView_specific_note.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
            TableRow.LayoutParams paramsSpecificNote = new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
            paramsSpecificNote.gravity = Gravity.CENTER;
            if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"),
                    parameters.getString("groupName"), families.get(l), "Note")) || screenWidth >= 600)
                header.addView(textView_specific_note, paramsSpecificNote);

            TableRow doseData = new TableRow(this);
            doseTable.addView(header);

            //General Dose

            if (dose.size() > 0) {
                show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l), "", "", notes_index, references,
                        references_index);
            }

            HashMap<String, ArrayList<String>> animal_information = new HashMap<String, ArrayList<String>>();
            if (db != null)
                animal_information = helper.read_animal_information(parameters.getString("drugName"),
                        parameters.getString("groupName"), families.get(l));

            String animalName;
            Object[] animalsName = animal_information.keySet().toArray();
            for (int i = 0; i < animalsName.length; i++) {
                doseData = new TableRow(this);

                //if exists animal name
                animalName = (String) animalsName[i];
                TextView textView_animal_name = new TextView(this);
                if (!animalName.equals("")) {

                    //Animal name

                    textView_animal_name.setText(animalName);
                    textView_animal_name.setSingleLine(false);
                    textView_animal_name.setTextColor(getResources().getColor(R.color.darkGray));
                    textView_animal_name.setTextSize(15);
                    textView_animal_name.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle());
                }

                //if exists category
                ArrayList<String> categories = animal_information.get(animalName);
                String animalCategory;
                for (int j = 0; j < categories.size(); j++) {

                    animalCategory = categories.get(j);

                    if (!animalCategory.equals("")) {

                        //Animal category

                        TextView textView_animal_category = new TextView(this);
                        textView_animal_category.setText(animalCategory);
                        textView_animal_category.setSingleLine(false);
                        textView_animal_category.setTextColor(Color.BLACK);
                        textView_animal_category.setTextSize(15);
                        textView_animal_category.setTypeface(Typeface.SANS_SERIF);
                        if (!animalName.equals("")) {
                            if (j == 0) {
                                TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams(
                                        TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                                if (screenWidth < 600
                                        && isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Posology")
                                        && isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Note"))
                                    paramsAnimalName.span = 3;
                                else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Posology")
                                        || isCollapsed(parameters.getString("drugName"),
                                                parameters.getString("groupName"), families.get(l), "Note")))
                                    paramsAnimalName.span = 4;
                                else
                                    paramsAnimalName.span = 5;

                                doseData.addView(textView_animal_name, paramsAnimalName);
                                doseTable.addView(doseData);
                            }

                            if (db != null)
                                dose = helper.read_dose_information(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), animalName,
                                        animalCategory);

                            doseData = new TableRow(this);
                            textView_animal_category.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
                            TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                            if (screenWidth < 600
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Posology")
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note"))
                                paramsCategoryName.span = 3;
                            else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), "Posology")
                                    || isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note")))
                                paramsCategoryName.span = 4;
                            else
                                paramsCategoryName.span = 5;
                            if (screenWidth < 600)
                                paramsCategoryName.leftMargin = 15;
                            else if (screenWidth >= 600 && screenWidth < 720)
                                paramsCategoryName.leftMargin = 20;
                            else
                                paramsCategoryName.leftMargin = 30;
                            doseData.addView(textView_animal_category, paramsCategoryName);
                            doseTable.addView(doseData);
                            doseData = new TableRow(this);
                            show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory, notes_index, references, references_index);

                            doseData = new TableRow(this);
                        } else {
                            if (db != null)
                                dose = helper.read_dose_information(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), animalName,
                                        animalCategory);

                            textView_animal_category.setTypeface(Typeface.SANS_SERIF,
                                    Typeface.DEFAULT_BOLD.getStyle());
                            textView_animal_category.setTextColor(getResources().getColor(R.color.darkGray));
                            TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                            if (screenWidth < 600
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Posology")
                                    && isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note"))
                                paramsCategoryName.span = 3;
                            else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), "Posology")
                                    || isCollapsed(parameters.getString("drugName"),
                                            parameters.getString("groupName"), families.get(l), "Note")))
                                paramsCategoryName.span = 4;
                            else
                                paramsCategoryName.span = 5;
                            doseData.addView(textView_animal_category, paramsCategoryName);
                            doseTable.addView(doseData);
                            doseData = new TableRow(this);
                            show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory, notes_index, references, references_index);

                            doseData = new TableRow(this);
                        }

                    }

                    if (!animalName.equals("") && animalCategory.equals("")) {
                        if (db != null)
                            dose = helper.read_dose_information(parameters.getString("drugName"),
                                    parameters.getString("groupName"), families.get(l), animalName,
                                    animalCategory);

                        TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams(
                                TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
                        if (screenWidth < 600
                                && isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Posology")
                                && isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Note"))
                            paramsAnimalName.span = 3;
                        else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"),
                                parameters.getString("groupName"), families.get(l), "Posology")
                                || isCollapsed(parameters.getString("drugName"),
                                        parameters.getString("groupName"), families.get(l), "Note")))
                            paramsAnimalName.span = 4;
                        else
                            paramsAnimalName.span = 5;
                        doseData.addView(textView_animal_name, paramsAnimalName);
                        doseTable.addView(doseData);
                        doseData = new TableRow(this);
                        show_dose(dose, doseTable, doseData, parameters.getString("drugName"),
                                parameters.getString("groupName"), families.get(l), animalName, animalCategory,
                                notes_index, references, references_index);

                        doseData = new TableRow(this);
                    }
                }

            }

            LinearLayout.LayoutParams paramsDoseTable = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            if (screenWidth >= 600) {
                paramsDoseTable.topMargin = 5;
                paramsDoseTable.leftMargin = 50;
                paramsDoseTable.rightMargin = 50;
            } else {
                paramsDoseTable.topMargin = 5;
                paramsDoseTable.leftMargin = 60;
                paramsDoseTable.rightMargin = 30;
            }
            layout_dose_information.addView(doseTable, paramsDoseTable);

            layoutDose.addView(layout_dose_information, layoutDose.getChildCount());
        }
        helper.close();

        //Notes
        additionalInformationInterface("GENERAL NOTES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);
        additionalInformationInterface("SPECIFIC NOTES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);
        //References
        additionalInformationInterface("REFERENCES", parameters.getString("drugName"),
                parameters.getString("groupName"), notes_index, references_index);

    }

}

From source file:de.grobox.liberario.TripsActivity.java

private void addTrips(final TableLayout main, List<Trip> trip_list, boolean append) {
    if (trip_list != null) {
        // reverse order of trips if they should be prepended
        if (!append) {
            ArrayList<Trip> tempResults = new ArrayList<Trip>(trip_list);
            Collections.reverse(tempResults);
            trip_list = tempResults;//from  w w  w  .  jav a  2 s  .  c  om
        }

        for (final Trip trip : trip_list) {
            final LinearLayout trip_layout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.trip,
                    null);
            TableRow row = (TableRow) trip_layout.findViewById(R.id.tripTableRow);

            // Locations
            TextView fromView = (TextView) row.findViewById(R.id.fromView);
            fromView.setText(trip.from.uniqueShortName());
            TextView toView = ((TextView) row.findViewById(R.id.toView));
            toView.setText(trip.to.uniqueShortName());

            // Departure Time and Delay
            TextView departureTimeView = (TextView) row.findViewById(R.id.departureTimeView);
            TextView departureDelayView = (TextView) row.findViewById(R.id.departureDelayView);
            if (trip.getFirstPublicLeg() != null) {
                LiberarioUtils.setDepartureTimes(this, departureTimeView, departureDelayView,
                        trip.getFirstPublicLeg().departureStop);
            } else {
                departureTimeView.setText(DateUtils.getTime(this, trip.getFirstDepartureTime()));
            }

            // Arrival Time and Delay
            TextView arrivalTimeView = (TextView) row.findViewById(R.id.arrivalTimeView);
            TextView arrivalDelayView = (TextView) row.findViewById(R.id.arrivalDelayView);
            if (trip.getLastPublicLeg() != null) {
                LiberarioUtils.setArrivalTimes(this, arrivalTimeView, arrivalDelayView,
                        trip.getLastPublicLeg().arrivalStop);
            } else {
                arrivalTimeView.setText(DateUtils.getTime(this, trip.getLastArrivalTime()));
            }

            // Duration
            TextView durationView = (TextView) trip_layout.findViewById(R.id.durationView);
            durationView
                    .setText(DateUtils.getDuration(trip.getFirstDepartureTime(), trip.getLastArrivalTime()));

            // Transports
            FlowLayout lineLayout = (FlowLayout) trip_layout.findViewById(R.id.lineLayout);

            // for each leg
            for (final Leg leg : trip.legs) {
                if (leg instanceof Trip.Public) {
                    LiberarioUtils.addLineBox(this, lineLayout, ((Public) leg).line);
                } else if (leg instanceof Trip.Individual) {
                    LiberarioUtils.addWalkingBox(this, lineLayout);
                }
            }

            // remember trip in view for onClick event
            trip_layout.setTag(trip);

            // make trip details fold out and in on click
            trip_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    View v = main.getChildAt(main.indexOfChild(view) + 1);

                    if (v != null) {
                        if (v.getVisibility() == View.GONE) {
                            v.setVisibility(View.VISIBLE);
                        } else if (v.getVisibility() == View.VISIBLE) {
                            v.setVisibility(View.GONE);
                        }
                    }
                }

            });
            trip_layout.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    selectTrip(view, trip_layout);
                    return true;
                }
            });

            // show more button for trip details
            final ImageView showMoreView = (ImageView) trip_layout.findViewById(R.id.showMoreView);
            showMoreView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectTrip(view, trip_layout);
                }
            });

            // Create container for trip details fragment
            FrameLayout fragmentContainer = new FrameLayout(this);
            fragmentContainer.setId(mContainerId);
            fragmentContainer.setVisibility(View.GONE);

            // Create a new Fragment to be placed in the activity layout
            TripDetailFragment tripDetailFragment = new TripDetailFragment();

            // In case this activity was started with special instructions from an
            // Intent, pass the Intent's extras to the fragment as arguments
            Bundle bundle = new Bundle();
            bundle.putSerializable("de.schildbach.pte.dto.Trip", trip);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.from", from);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.to", to);
            tripDetailFragment.setArguments(bundle);

            // Add the fragment to the 'fragment_container' FrameLayout
            getSupportFragmentManager().beginTransaction().add(mContainerId, tripDetailFragment).commit();

            mContainerId++;

            if (append) {
                trip_layout.addView(LiberarioUtils.getDivider(this));
                main.addView(trip_layout);
                main.addView(fragmentContainer);
            } else {
                trip_layout.addView(LiberarioUtils.getDivider(this), 0);
                main.addView(trip_layout, 0);
                main.addView(fragmentContainer, 1);
            }
        } // end foreach trip

    } else {
        // TODO offer option to query again for trips
    }
}