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:Main.java

public static void setTime(Activity activity, TextView view, long millis) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT;
    if (DateFormat.is24HourFormat(activity)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }//  w ww  . j a  v a  2  s  . c  om

    // Unfortunately, DateUtils doesn't support a timezone other than the
    // default timezone provided by the system, so we have this ugly hack
    // here to trick it into formatting our time correctly. In order to
    // prevent all sorts of craziness, we synchronize on the TimeZone class
    // to prevent other threads from reading an incorrect timezone from
    // calls to TimeZone#getDefault()
    // TODO fix this if/when DateUtils allows for passing in a timezone
    String timeString;
    synchronized (TimeZone.class) {
        timeString = DateUtils.formatDateTime(activity, millis, flags);
        TimeZone.setDefault(null);
    }

    view.setTag(millis);
    view.setText(timeString);
}

From source file:Main.java

public static int applyNewLineCharacter(TextView textView) {
    Paint paint = textView.getPaint();
    String text = (String) textView.getText();
    int frameWidth = getPixelFromDp(textView, 120f);
    int startIndex = 0;
    int endIndex = paint.breakText(text, true, frameWidth, null);
    String save = text.substring(startIndex, endIndex);
    // Count line of TextView
    int lines = 1;

    while (true) {
        // Set new start index
        startIndex = endIndex;/*from   ww w .j ava2s  .  c  om*/
        // Get substring the remaining of text
        text = text.substring(startIndex);

        if (text.length() == 0) {
            break;
        } else {
            lines++;
        }

        // Calculate end of index that fits
        endIndex = paint.breakText(text, true, frameWidth, null);
        // Append substring that fits into the frame
        save += "\n" + text.substring(0, endIndex);
    }
    // Set text to TextView
    textView.setText(save);

    return lines;
}

From source file:com.google.zxing.client.android.TestActivity.java

@Override
protected void onCreate(Bundle savedBundleInstance) {
    super.onCreate(savedBundleInstance);
    TextView tv = new TextView(this);
    tv.setText(getIntent().getStringExtra("test"));
    setContentView(tv);//from   w  w w. j av a 2 s  .c  o  m
}

From source file:SecondActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    TextView textView = (TextView) findViewById(R.id.textViewText);
    textView.setText(getIntent().getStringExtra(Intent.EXTRA_TEXT));
}

From source file:DictionaryAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    textView.setText(cursor.getString(getCursor().getColumnIndex("word")));
}

From source file:MainActivity.java

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

    TextView textViewRaw = (TextView) findViewById(R.id.textViewRaw);
    textViewRaw.setText(getText(this.getResources().openRawResource(R.raw.raw_text)));

    TextView textViewAsset = (TextView) findViewById(R.id.textViewAsset);
    try {//www  .  j  a va2s .c om
        textViewAsset.setText(getText(this.getAssets().open("asset_text.txt")));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();// w w w .  j  a va 2  s . c o m
    TextView valueTV = new TextView(context);
    valueTV.setText("IM:" + content.optString(TEXT));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}

From source file:com.jdom.axis.and.allies.view.DetailsViewActivity.java

@SuppressWarnings("unchecked")
private void writeOutCountries(PlayableCountry playableCountry, int countriesViewId) {
    TextView textView = (TextView) findViewById(countriesViewId);
    textView.setText(StringUtils.join(playableCountry.getOwnedTerritories()));
}

From source file:com.example.util.Utils.java

/**
 * Show toast information/*from  w  w w .ja v  a  2  s  .  c  om*/
 * 
 * @param context
 *            application context
 * @param text
 *            the information which you want to show
 * @return show toast dialog
 */
public static void makeEventToast(Context context, String text, boolean isLongToast) {

    Toast toast = null;
    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:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Alert animation in//from w  w  w  .j  av  a 2  s.c o m
 * @param configuration describes all device configuration information
 * @param alertView     View Resources to animate
 * @param textView      alert message to be viewed
 * @param mainView      ViewGroup resources
 * @param text          message to be displayed
 */
private static void animIn(final Configuration configuration, final View alertView, TextView textView,
        final ViewGroup mainView, String text) {
    // Colors
    textView.setTextColor(configuration.getColorTextResId());
    alertView.setBackgroundColor(configuration.getColorBackgroundResId());

    // Content Description
    alertView.setContentDescription(configuration.getMessageType());

    // Setting the text
    textView.setText(text);

    // Animation In
    if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
        animViews(alertView, mainView, configuration, 0, configuration.getHeight(), true);
    } else {
        animViews(alertView, mainView, configuration, mainView.getHeight() - configuration.getHeight(),
                -configuration.getHeight(), true);
    }

    // Delayed animation out
    if (configuration.isCloseable()) {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                animOut(configuration, mainView, alertView);
            }
        }, configuration.getDuration());
    }
}