Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

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

public void createTextViewTherapeutic() {
    therapeuticGroup = new TextView(this);
    therapeuticGroup.setTextSize(18);//from  w w w . j a va2  s .com
    therapeuticGroup.setTypeface(Typeface.SANS_SERIF);
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private TextView makeTextView(String text) {
    TextView textView = new TextView(getActivity());
    textView.setText(text);/*from   www  . ja va  2  s  .co m*/
    textView.setLayoutParams(FIXED_WIDTH_COLS_LAYOUT);
    return textView;
}

From source file:android.support.v7.widget.Toolbar.java

/**
 * Set the title of this toolbar.//  ww  w .j a v a  2s  . c o m
 *
 * <p>A title should be used as the anchor for a section of content. It should
 * describe or name the content being viewed.</p>
 *
 * @param title Title to set
 */
public void setTitle(CharSequence title) {
    if (!TextUtils.isEmpty(title)) {
        if (mTitleTextView == null) {
            final Context context = getContext();
            mTitleTextView = new TextView(context);
            mTitleTextView.setSingleLine();
            mTitleTextView.setEllipsize(TextUtils.TruncateAt.END);
            if (mTitleTextAppearance != 0) {
                mTitleTextView.setTextAppearance(context, mTitleTextAppearance);
            }
            if (mTitleTextColor != 0) {
                mTitleTextView.setTextColor(mTitleTextColor);
            }
        }
        if (mTitleTextView.getParent() == null) {
            addSystemView(mTitleTextView);
            updateChildVisibilityForExpandedActionView(mTitleTextView);
        }
    } else if (mTitleTextView != null && mTitleTextView.getParent() != null) {
        removeView(mTitleTextView);
    }
    if (mTitleTextView != null) {
        mTitleTextView.setText(title);
    }
    mTitleText = title;
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Displays a multiple choice question to the user.
 * @param question the question to be displayed
 * @param linearLayoutInsideAScrollView the view to add the question to
 * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5
 *///from  ww  w .ja  v a 2  s.c  o m
private void makeMultipleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView,
        int ordinal) {
    LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView);
    String questionText = question.getTitle();
    List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers();
    Collections.sort(possibleAnswers);

    TextView questionView = new TextView(getActivity());
    questionView.setText(ordinal + ". " + questionText);
    if (question.isMandatory())
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory);
    else
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle);
    questionContainer.addView(questionView);
    mQuestionTitleMappings.put(question, questionView);

    Log.i(LOG_TAG, "questionView = " + questionView.getText());

    final HashSet<String> madeAnswers = new HashSet<String>();
    madeAnswers.addAll(Arrays.asList(question.getAnswer().split(",")));
    madeAnswers.remove(""); // paranoia

    final CheckBox[] checkBoxs = new CheckBox[possibleAnswers.size()];
    for (int i = 0; i < checkBoxs.length; i++) {
        final PossibleAnswer possibleAnswer = possibleAnswers.get(i);
        final String possibleAnswerId = String.valueOf(possibleAnswer.getId());
        checkBoxs[i] = new CheckBox(getActivity());
        if (i % 2 == 0)
            checkBoxs[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray));
        checkBoxs[i].setText(possibleAnswer.getTitle());
        checkBoxs[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle);
        if (madeAnswers.contains(possibleAnswerId))
            checkBoxs[i].setChecked(true);

        // click handling
        checkBoxs[i].setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    madeAnswers.add(possibleAnswerId);
                else
                    madeAnswers.remove(possibleAnswerId);
                String newAnswer = "";
                for (String madeAnswer1 : madeAnswers)
                    newAnswer = newAnswer + "," + madeAnswer1;
                if (!newAnswer.isEmpty())
                    newAnswer = newAnswer.substring(1); // remove the leading ","
                question.setAnswer(newAnswer);
            }
        });

        checkBoxs[i].setVisibility(View.VISIBLE);
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            checkBoxs[i].setEnabled(false);
        questionContainer.addView(checkBoxs[i]);
    }
}

From source file:android.support.v7ox.widget.Toolbar.java

/**
 * Set the title of this toolbar./*from w w  w  .j av  a  2s .  c  o m*/
 *
 * <p>A title should be used as the anchor for a section of content. It should
 * describe or name the content being viewed.</p>
 *
 * @param title Title to set
 */
public void setTitle(CharSequence title) {
    if (!TextUtils.isEmpty(title)) {
        if (mTitleTextView == null) {
            final Context context = getContext();
            mTitleTextView = new TextView(context);
            mTitleTextView.setSingleLine();
            mTitleTextView.setEllipsize(TextUtils.TruncateAt.END);
            if (mTitleTextAppearance != 0) {
                mTitleTextView.setTextAppearance(context, mTitleTextAppearance);
            }
            if (mTitleTextColor != 0) {
                mTitleTextView.setTextColor(mTitleTextColor);
            }
        }
        if (!isChildOrHidden(mTitleTextView)) {
            addSystemView(mTitleTextView, true);
        }
    } else if (mTitleTextView != null && isChildOrHidden(mTitleTextView)) {
        removeView(mTitleTextView);
        mHiddenViews.remove(mTitleTextView);
    }
    if (mTitleTextView != null) {
        mTitleTextView.setText(title);
    }
    mTitleText = title;
}

From source file:fr.cph.chicago.activity.StationActivity.java

/**
 * Draw line/*ww w .  ja v  a  2  s .com*/
 * 
 * @param eta
 *            the eta
 */
private final void drawLine3(final Eta eta) {
    TrainLine line = eta.getRouteName();
    Stop stop = eta.getStop();
    int line3Padding = (int) getResources().getDimension(R.dimen.activity_station_stops_line3);
    Integer viewId = mIds.get(line.toString() + "_" + stop.getDirection().toString());
    // viewId might be not there if CTA API provide wrong data
    if (viewId != null) {
        LinearLayout line3View = (LinearLayout) findViewById(viewId);
        Integer id = mIds.get(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName());
        if (id == null) {
            LinearLayout insideLayout = new LinearLayout(this);
            insideLayout.setOrientation(LinearLayout.HORIZONTAL);
            insideLayout.setLayoutParams(mParamsStop);
            int newId = Util.generateViewId();
            insideLayout.setId(newId);
            mIds.put(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(), newId);

            TextView stopName = new TextView(this);
            stopName.setText(eta.getDestName() + ": ");
            stopName.setTextColor(getResources().getColor(R.color.grey));
            stopName.setPadding(line3Padding, 0, 0, 0);
            insideLayout.addView(stopName);

            TextView timing = new TextView(this);
            timing.setText(eta.getTimeLeftDueDelay() + " ");
            timing.setTextColor(getResources().getColor(R.color.grey));
            timing.setLines(1);
            timing.setEllipsize(TruncateAt.END);
            insideLayout.addView(timing);

            line3View.addView(insideLayout);
        } else {
            LinearLayout insideLayout = (LinearLayout) findViewById(id);
            TextView timing = (TextView) insideLayout.getChildAt(1);
            timing.setText(timing.getText() + eta.getTimeLeftDueDelay() + " ");
        }
        line3View.setVisibility(View.VISIBLE);
    }
}

From source file:com.flipzu.flipzu.Player.java

private void displayComment(Hashtable<String, String> comment) {
    if (comment == null)
        return;//from  w  w w. j  a  va2  s . c  o m

    final LinearLayout com_layout = (LinearLayout) findViewById(R.id.comments_layout);
    TextView comment_tv = new TextView(Player.this);
    comment_tv.setText(comment.get("username") + ": " + comment.get("comment"), TextView.BufferType.SPANNABLE);
    comment_tv.setTextColor(Color.parseColor("#656565"));
    Spannable comment_span = (Spannable) comment_tv.getText();
    comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#597490")), 0,
            comment.get("username").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    comment_tv.setText(comment_span);
    com_layout.addView(comment_tv);
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void showOfflinePNRStatus(String trainDetails, ArrayList<String> passnDetails) {
    LinearLayout ll = new LinearLayout(mActivity);

    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);
    TextView tvTrainDetails = new TextView(mActivity);
    TextView[] tvPassnDetails = new TextView[passnDetails.size()];

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);//from ww w  .  j a  v a2 s . c  om
    textViewPsnDtls.setText("Passenger Details");
    tvTrainDetails.setText(trainDetails);
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    tvTrainDetails.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    tvTrainDetails.setPadding(10, 10, 10, 10);

    tvTrainDetails.setBackgroundResource(R.drawable.card_background);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);

    ll.addView(tvTrainDetails);
    ll.addView(textViewPsnDtls);
    for (int i = 0; i < passnDetails.size(); ++i) {
        tvPassnDetails[i] = new TextView(mActivity);
        tvPassnDetails[i].setText(passnDetails.get(i));
        tvPassnDetails[i].setPadding(10, 10, 10, 10);
        tvPassnDetails[i].setBackgroundResource(R.drawable.card_background);
        tvPassnDetails[i].setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        ll.addView(tvPassnDetails[i]);
    }
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
}

From source file:android.support.designox.widget.TextInputLayout.java

/**
 * Whether the character counter functionality is enabled or not in this layout.
 *
 * @attr ref android.support.designox.R.styleable#TextInputLayout_counterEnabled
 *///from  ww w  .ja va 2s  . c  o  m
public void setCounterEnabled(boolean enabled) {
    if (mCounterEnabled != enabled) {
        if (enabled) {
            mCounterView = new TextView(getContext());
            mCounterView.setMaxLines(1);
            try {
                mCounterView.setTextAppearance(getContext(), mCounterTextAppearance);
            } catch (Exception e) {
                // Probably caused by our theme not extending from Theme.Design*. Instead
                // we manually set something appropriate
                mCounterView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Caption);
                mCounterView.setTextColor(
                        ContextCompat.getColor(getContext(), R.color.design_textinput_error_color_light));
            }
            addIndicator(mCounterView, -1);
            if (mEditText == null) {
                updateCounter(0);
            } else {
                updateCounter(mEditText.getText().length());
            }
        } else {
            removeIndicator(mCounterView);
            mCounterView = null;
        }
        mCounterEnabled = enabled;
    }
}

From source file:it.crs4.most.ehrlib.WidgetProvider.java

/**
 * Builds the title view./*  w  ww .  j  av  a2s.c  o m*/
 *
 * @param context the context
 * @param title the title
 * @return the view
 */
private View buildTitleView(Context context, String title) {
    titleView = new TextView(context);
    titleView.setText(title);
    titleView.setTextColor(Color.WHITE);
    titleView.setTextSize(22);
    titleView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    titleView.setTypeface(null, Typeface.BOLD);
    titleView.setGravity(Gravity.CENTER);

    return titleView;
}