Example usage for android.widget TextView setText

List of usage examples for android.widget TextView setText

Introduction

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

Prototype

@android.view.RemotableViewMethod
public final void setText(@StringRes int resid) 

Source Link

Document

Sets the text to be displayed using a string resource identifier.

Usage

From source file:com.andrewshu.android.reddit.common.Common.java

public static void showErrorToast(String error, int duration, Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Toast t = new Toast(context);
    t.setDuration(duration);/*from  ww w. ja  v a  2  s  .c  o  m*/
    View v = inflater.inflate(R.layout.error_toast, null);
    TextView errorMessage = (TextView) v.findViewById(R.id.errorMessage);
    errorMessage.setText(error);
    t.setView(v);
    t.show();
}

From source file:Main.java

static void showPermissionStatus(TextView tvOutput, String[] permissions, int[] grantResults) {
    StringBuilder stringBuilder = new StringBuilder();

    for (int i = 0; i < permissions.length; i++) {
        String permission = permissions[i];
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        if (granted) {
            stringBuilder.append(permission).append(" was granted").append("\n");
        } else {/*w  w w . j a va 2s .c o  m*/
            stringBuilder.append(permission).append(" wasn't granted").append("\n");
        }
    }

    Log.d("rx_permissions_result", stringBuilder.toString());
    tvOutput.setText(stringBuilder.toString());
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void updateImageFont(JSONParcelable imageData, TextView imageScore) {
    try {/*from   w ww .java 2 s .co m*/
        if (!imageData.getJSONObject().has("vote")) {
            imageScore.setVisibility(View.GONE);
            return;
        }
        if (imageData.getJSONObject().getString("vote") != null
                && imageData.getJSONObject().getString("vote").equals("up"))
            imageScore.setText(Html.fromHtml("<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                    + " points </font> (<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                    + "</font>/<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs"))
                    + "</font>)"));
        else if (imageData.getJSONObject().getString("vote") != null
                && imageData.getJSONObject().getString("vote").equals("down"))
            imageScore.setText(Html.fromHtml("<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                    + " points </font> (<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                    + "</font>/<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs"))
                    + "</font>)"));
        else
            imageScore.setText(Html.fromHtml(
                    NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                            + " points (<font color=#89c624>"
                            + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                            + "</font>/<font color=#ee4444>" + NumberFormat.getIntegerInstance()
                                    .format(imageData.getJSONObject().getInt("downs"))
                            + "</font>)"));
    } catch (JSONException e) {
        Log.e("Error font!", e.toString());
    }
}

From source file:csic.ceab.movelab.beepath.Util.java

/**
 * Displays a brief message on the phone screen. Taken from Human Mobility
 * Project code written by Chang Y. Chung and Necati E. Ozgencil.
 * //ww w. j  a v a2  s.  c  o m
 * @param context
 *            Interface to application environment
 * @param msg
 *            The message to be displayed to the user
 */
public static void toast(Context context, String msg) {

    TextView tv = new TextView(context);
    tv.setText(msg);
    Drawable bknd = context.getResources().getDrawable(R.drawable.white_border);
    tv.setBackgroundDrawable(bknd);
    tv.setPadding(20, 20, 20, 20);
    tv.setTextSize(20);

    Toast t = new Toast(context);
    t.setDuration(Toast.LENGTH_LONG);
    t.setView(tv);
    t.show();
}

From source file:com.bbxiaoqu.api.util.Utils.java

public static void makeEventToast(Context context, String text, boolean isLongToast) {

    Toast toast = null;/*w w  w  . j  a v a2s . c  o m*/
    if (isLongToast) {
        toast = Toast.makeText(context, "", Toast.LENGTH_LONG);
    } else {
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    View v = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
    TextView textView = (TextView) v.findViewById(R.id.text);
    textView.setText(text);
    toast.setView(v);
    toast.show();
}

From source file:Main.java

public static void animateTextChange(final TextView view, final String toText) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);//from   ww w .  ja  va2  s.  c  o  m
    alpha.setInterpolator(new AccelerateDecelerateInterpolator());
    restore.setDuration(DURATION_SHORT);
    restore.setInterpolator(new AccelerateDecelerateInterpolator());
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            view.setText(toText);
            restore.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setText(toText);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    alpha.start();
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void updateInfoFont(JSONParcelable imageData, TextView infoText) {
    try {/*w  w w .j a  va2  s  .c  o  m*/
        String albumText = "";
        if (imageData.getJSONObject().has("is_album") && imageData.getJSONObject().getBoolean("is_album"))
            albumText = "[album] ";
        if (!imageData.getJSONObject().getString("section").equals("null"))
            albumText += "/r/" + imageData.getJSONObject().getString("section") + " " + Html.fromHtml("&#8226;")
                    + " ";
        Calendar calendar = Calendar.getInstance();
        long now = calendar.getTimeInMillis();
        infoText.setText(albumText
                + DateUtils.getRelativeTimeSpanString(imageData.getJSONObject().getLong("datetime") * 1000, now,
                        DateUtils.MINUTE_IN_MILLIS)
                + " " + Html.fromHtml("&#8226;") + " ");
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
}

From source file:com.android.mms.ui.ConversationList.java

/**
 * Build and show the proper delete thread dialog. The UI is slightly different
 * depending on whether there are locked messages in the thread(s) and whether we're
 * deleting a single thread or all threads.
 * @param listener gets called when the delete button is pressed
 * @param deleteAll whether to show a single thread or all threads UI
 * @param hasLockedMessages whether the thread(s) contain locked messages
 * @param context used to load the various UI elements
 *//*  w  w  w . j ava 2  s .  c o m*/
public static void confirmDeleteThreadDialog(final DeleteThreadListener listener, boolean deleteAll,
        boolean hasLockedMessages, Context context) {
    View contents = View.inflate(context, R.layout.delete_thread_dialog_view, null);
    TextView msg = (TextView) contents.findViewById(R.id.message);
    msg.setText(deleteAll ? R.string.confirm_delete_all_conversations : R.string.confirm_delete_conversation);
    final CheckBox checkbox = (CheckBox) contents.findViewById(R.id.delete_locked);
    if (!hasLockedMessages) {
        checkbox.setVisibility(View.GONE);
    } else {
        listener.setDeleteLockedMessage(checkbox.isChecked());
        checkbox.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                listener.setDeleteLockedMessage(checkbox.isChecked());
            }
        });
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.confirm_dialog_title).setIcon(android.R.drawable.ic_dialog_alert)
            .setCancelable(true).setPositiveButton(R.string.delete, listener)
            .setNegativeButton(R.string.no, null).setView(contents).show();
}

From source file:Main.java

public static void animateTextChange(final TextView view, @IdRes final int toText, final Runnable rWhenEnd) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);//from   ww  w.  j  ava2s.co  m
    alpha.setInterpolator(new AccelerateDecelerateInterpolator());
    restore.setDuration(DURATION_SHORT);
    restore.setInterpolator(new AccelerateDecelerateInterpolator());
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Do nothing.
        }

        @SuppressWarnings("ResourceType")
        @Override
        public void onAnimationEnd(Animator animation) {
            view.setText(toText);
            restore.start();
        }

        @SuppressWarnings("ResourceType")
        @Override
        public void onAnimationCancel(Animator animation) {
            view.setText(toText);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    if (rWhenEnd != null)
        restore.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                rWhenEnd.run();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                rWhenEnd.run();
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    alpha.start();
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog containing the code received by goo.gl if any, or an error
 * message stating that the pairing operation failed.
 * //  w  w w . ja  v  a  2s .  c  om
 * @param googl
 *            the pairing code retrieved by goo.gl
 * @param activity
 *            the caller activity
 */
public static void onObtainPairingCode(final String googl, final MainActivity activity) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            if (googl != null) {
                View layout = View.inflate(getContext(), R.layout.pairing_code_dialog, null);
                TextView message = (TextView) layout.findViewById(R.id.pairingCode);
                Typeface typeFace = Typeface.createFromAsset(activity.getAssets(), CUSTOM_TYPEFACE_PATH);
                message.setTypeface(typeFace);
                message.setText(googl);
                builder.setView(layout);
            } else {
                builder.setMessage(getResources().getString(R.string.code_dialog_fail));
            }
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (googl != null) {
                        Resources res = getResources();
                        String howManyTotal = res.getQuantityString(R.plurals.added_device,
                                activity.getInboundDevicesCount(), activity.getInboundDevicesCount());
                        Toast.makeText(getActivity(), res.getString(R.string.device_paired, howManyTotal),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
            return builder.create();
        }
    }.show(activity.getSupportFragmentManager(), "resultCode");
}