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.mikecorrigan.trainscorekeeper.FragmentSummary.java

private void updateUi() {
    Log.vc(VERBOSE, TAG, "updateUi");

    if (game == null) {
        Log.w(TAG, "updateUi: no game, this=" + this);
        return;//from  ww  w.j av a2  s .c o m
    }

    if (tableLayout == null) {
        Log.w(TAG, "updateUi: no table, this=" + this);
        return;
    }

    // Subtract one to skip the header in the allocation.
    final int numRows = tableLayout.getChildCount() - 1;
    final TableRow headerRow = (TableRow) tableLayout.getChildAt(0);
    final int numCols = headerRow.getChildCount();

    String[] header = new String[numCols];
    int[][] scores = new int[numRows][numCols];

    game.getSummary(header, scores);

    for (int c = 0; c < numCols; c++) {
        TextView textView = (TextView) headerRow.getChildAt(c);
        textView.setText(header[c]);
    }

    for (int r = 0; r < numRows; r++) {
        // Add one to the row index to skip the header.
        final TableRow row = (TableRow) tableLayout.getChildAt(r + 1);

        for (int c = 0; c < numCols; c++) {
            TextView textView = (TextView) row.getChildAt(c);
            textView.setText(Integer.toString(scores[r][c]));
        }
    }
}

From source file:com.mychild.view.Parent.CustomTabActivity.java

public void setUpTab() {
    final TabHost tabHost = (TabHost) findViewById(R.id.tabhost2);
    tabHost.setup();//from www.  j  av a 2 s .  com
    tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    class TabDef {
        public final String Indicator;//, Content;

        public TabDef(String Indicator, ListView lv) {
            this.Indicator = Indicator;
            //this.Content = Content;

        } /*TabDef*/
    }
    ; /*TabDef*/
    for (TabDef thisTab : new TabDef[] { new TabDef("Exams", examsListView),
            new TabDef("Results", examsListView) }) {

        //            final TextView contentview = new TextView(this);
        //            contentview.setText(thisTab.Content);

        View indicatorview = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_plain, null);
        TextView tabTitle = (TextView) indicatorview.findViewById(R.id.tabsText);
        tabTitle.setText(thisTab.Indicator);

        tabHost.addTab(tabHost.newTabSpec(thisTab.Indicator).setIndicator(indicatorview)
                .setContent(new TabHost.TabContentFactory() {
                    public View createTabContent(String tag) {
                        Log.i("Tagggggg:", tag);

                        if (tag == "Exams") {
                            return examsListView;
                        } else {
                            return examsListView;
                        }
                    } /*createTabContent*/
                }));/*TabContentFactory*/

    } /*for*/
}

From source file:gov.wa.wsdot.android.wsdot.ui.NewsFragment.java

public void onLoadFinished(Loader<ArrayList<NewsItem>> loader, ArrayList<NewsItem> data) {

    if (!data.isEmpty()) {
        mAdapter.setData(data);//from ww w  . j a  v  a2 s . c  om
    } else {
        TextView t = (TextView) mEmptyView;
        t.setText(R.string.no_connection);
        getListView().setEmptyView(mEmptyView);
    }

    swipeRefreshLayout.setRefreshing(false);
}

From source file:com.savedollars.ProductStockDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));

    if (JSONData != null) {
        parseJsonData(JSONData);/*w  w  w . jav a 2 s  . c  om*/
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.pdtstockview);
    // Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator it = sortedMap.keySet().iterator();
    int rowIndex = 0;

    PDT_INFO = new String[totalCount][2];
    while (it.hasNext()) {

        String key = ProductTotalPriceDisplay.merchantNames[rowIndex];
        String availability = (String) availabilityMap.get(key);
        PDT_INFO[rowIndex][0] = key;
        PDT_INFO[rowIndex][1] = availability;
        rowIndex++;
        it.next();
    }

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);

    final ListView lv = getListView();

    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            lv.getItemAtPosition(position);
            String pdtKey = PDT_INFO[position][0];
            String merchantLink = (String) merchantLinkMap.get(pdtKey);

            Uri uri = Uri.parse(merchantLink);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);

        }
    });

}

From source file:com.savedollars.ProductPriceDisplay.java

@SuppressWarnings({ "rawtypes", "unused" })
@Override//  w ww. ja va 2 s  .  c  om
protected void onCreate(Bundle savedInstanceState) {

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));
    if (JSONData != null) {
        parseJsonData(JSONData);
    }
    super.onCreate(savedInstanceState);

    setContentView(R.layout.pdtpriceview);

    // Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator objMapIterator = sortedMap.entrySet().iterator();
    int rowIndex = 0;

    PDT_INFO = new String[totalCount][2];

    while (objMapIterator.hasNext()) {
        Map.Entry keyValuePairs = (Map.Entry) objMapIterator.next();
        String key = ProductTotalPriceDisplay.merchantNames[rowIndex];

        PDT_INFO[rowIndex][0] = key;
        PDT_INFO[rowIndex][1] = "$" + sortedMap.get(key);
        rowIndex++;
    }

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);

    final ListView lv = getListView();

    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            lv.getItemAtPosition(position);
            String pdtKey = PDT_INFO[position][0];
            String merchantLink = (String) merchantLinkMap.get(pdtKey);

            Uri uri = Uri.parse(merchantLink);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);

        }
    });

}

From source file:com.example.nestedarchetypeactivityexample.InnerArchetypeViewerActivity.java

/**
  * Show info dialog./*from  w  ww  .j av  a 2  s.c o m*/
  *
  * @param content the content
  */
private void showInfoDialog(String content) {
    final Dialog dialog = new Dialog(this);
    dialog.setTitle("Json Adl Structure");
    dialog.setContentView(R.layout.custom_dialog);
    TextView dialogText = (TextView) dialog.findViewById(R.id.dialogText);
    dialogText.setMovementMethod(new ScrollingMovementMethod());
    dialogText.setText(content);

    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    dialogButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }
    });

    dialog.show();
}

From source file:com.nanostuffs.yurdriver.fragment.BankDetails.java

private void actionBarDetails() {
    getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    final View addView = getActivity().getLayoutInflater().inflate(R.layout.my_custom_navigation, null);

    TextView title = (TextView) addView.findViewById(R.id.title);
    title.setText("REGISTRATION");
    ImageView back = (ImageView) addView.findViewById(R.id.back);
    back.setOnClickListener(new OnClickListener() {

        @Override//from  w  w  w  .j a v  a  2  s  . com
        public void onClick(View v) {
            // TODO Auto-generated method stub
            FragmentManager manager = getActivity().getSupportFragmentManager();
            manager.popBackStack();
        }
    });
    getActivity().getActionBar().setCustomView(addView);
}

From source file:com.hybris.mobile.activity.OrderDetailActivity.java

private void updateUI() {
    String pageTitle = getString(R.string.order_completed_text);
    if (getIntent().hasExtra(DataConstants.ORDER_ID)) {
        pageTitle += " " + mOrderDetails.getCode();

        String strOrderStatus = "<b>" + mOrderDetails.getStatusDisplay() + "</b>";
        Calendar cal = DateUtil.fromIso8601(mOrderDetails.getCreated());
        strOrderStatus = strOrderStatus + "<br />" + getString(R.string.placed_on_placeholder_text) + " "
                + cal.getTime().toString();
        TextView orderStatus = (TextView) findViewById(R.id.lbl_orderStatusView);
        orderStatus.setText(Html.fromHtml(strOrderStatus));
        findViewById(R.id.containerOrderStatus).setVisibility(View.VISIBLE);
        findViewById(R.id.dividerOrderStatus).setVisibility(View.VISIBLE);

    }// w w w.  j av a2s.c  o  m
    setTitle(pageTitle);

    CartDeliveryAddress address = mOrderDetails.getDeliveryAddress();

    // delivery address section
    String strList = "";
    if (address != null) {
        String firstName = address.getTitle();
        String lastName = address.getLastName();
        String title = address.getFirstName();

        // strList = "Delivery address\n\n";
        strList = "<b>" + strList + title + " " + firstName + " " + lastName + "</b>";

        strList += StringUtils.isNotBlank(address.getLine1()) ? "<br />" + address.getLine1() : "";
        strList += StringUtils.isNotBlank(address.getLine2()) ? "<br />" + address.getLine2() : "";
        strList += StringUtils.isNotBlank(address.getTown()) ? "<br />" + address.getTown() : "";
        strList += StringUtils.isNotBlank(address.getPostalCode()) ? "<br />" + address.getPostalCode() : "";
        strList += (address.getCountry() != null && StringUtils.isNotBlank(address.getCountry().getName()))
                ? "<br />" + address.getCountry().getName()
                : "";

        TextView addressView = (TextView) findViewById(R.id.lbl_addressView);
        addressView.setText(Html.fromHtml(strList));
    }

    // delivery mode section
    CartDeliveryMode deliveryMode = mOrderDetails.getDeliveryMode();
    if (deliveryMode != null) {
        strList = "<b>" + deliveryMode.getName() + "</b><br />" + deliveryMode.getDescription() + "<br />"
                + deliveryMode.getDeliveryCost().getFormattedValue();
        TextView deliveryView = (TextView) findViewById(R.id.lbl_deliveryMethod);
        deliveryView.setText(Html.fromHtml(strList));
    }

    // payment section
    CartPaymentInfo payment = mOrderDetails.getPaymentInfo();
    if (payment != null) {
        String accountHolderName = payment.getAccountHolderName();
        String cardType = payment.getCardType().getName();
        String cardNumber = payment.getCardNumber();

        strList = "<b>" + accountHolderName + "</b><br />" + cardNumber + "<br />" + cardType;
        TextView paymentView = (TextView) findViewById(R.id.lbl_paymentDetails);
        paymentView.setText(Html.fromHtml(strList));
    }

    TextView subtotal = (TextView) findViewById(R.id.lbl_subTotal);
    subtotal.setText(mOrderDetails.getSubTotal().getFormattedValue());

    TextView totaltax = (TextView) findViewById(R.id.lbl_totalTax);
    totaltax.setText(mOrderDetails.getTotalTax().getFormattedValue());

    TextView deliveryprice = (TextView) findViewById(R.id.lbl_deliveryCharge);
    deliveryprice.setText(mOrderDetails.getDeliveryCost().getFormattedValue());

    TextView totalprice = (TextView) findViewById(R.id.lbl_totalPriceWithTax);
    totalprice.setText(mOrderDetails.getTotalPrice().getFormattedValue());

}

From source file:com.example.office.ui.calendar.EventFragment.java

/**
  * Fills fragment content with events/*from w  w w .ja  va2  s .  co m*/
  *
  * @param root Root view for current fragment
  */
private void displayEvent(View root) {
    try {
        //Populate fragment fields with event properties
        TextView subjectView = (TextView) root.findViewById(R.id.event_fragment_subject);
        subjectView.setText(event.getSubject());

        // Resolving Attendees
        TextView attendeesView = (TextView) root.findViewById(R.id.event_fragment_participants);
        StringBuilder attendeesStr = new StringBuilder(getActivity().getString(R.string.event_attendees));
        Collection<Attendee> attendees = event.getAttendees();
        if (attendees != null && !attendees.isEmpty()) {
            for (Attendee attendee : attendees) {
                if (!TextUtils.isEmpty(attendee.getName())) {
                    attendeesStr.append(attendee.getName())
                            .append(getActivity().getString(R.string.event_addressee_delimiter));
                }
            }
        }
        attendeesView.setText(attendeesStr.toString());

        // Resolving Start and end of the event
        TextView dateStartView = (TextView) root.findViewById(R.id.event_fragment_date_start);
        TextView dateEndView = (TextView) root.findViewById(R.id.event_fragment_date_end);
        Date start = event.getStart();
        Date end = event.getEnd();
        final String pattern = "yyyy-MM-dd HH:mm";
        final SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
        if (start != null && end != null) {
            dateStartView.setText(
                    String.format(getActivity().getString(R.string.event_date_start), formatter.format(start)));
            dateEndView.setText(
                    String.format(getActivity().getString(R.string.event_date_end), formatter.format(end)));
        }

        // resolving location
        TextView locationView = (TextView) root.findViewById(R.id.event_fragment_location);
        String location = "Location: ";
        if (event.getLocation() == null || TextUtils.isEmpty(event.getLocation().getDisplayName())) {
            location += "unknown";
        } else {
            location += event.getLocation().getDisplayName();
        }
        locationView.setText(location);

        //Resolving event message
        WebView webview = (WebView) root.findViewById(R.id.event_fragment_content);
        if (event.getBody().getContentType() == BodyType.HTML) {
            webview.loadData(event.getBody().getContent(),
                    getActivity().getString(R.string.mime_type_text_html), CharEncoding.UTF_8);
        } else {
            webview.loadData(event.getBody().getContent(),
                    getActivity().getString(R.string.mime_type_text_plain), CharEncoding.UTF_8);
        }
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".displayEvent(): Error.");
    }
}

From source file:Main.java

/**
 * Make UI TextView a html link./*  w  ww .  j a  va  2s. co  m*/
 * 
 * @param context the context
 * @param textView the text view
 * @param html the html containing link info
 */
public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) {
    textView.setLinksClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (final URLSpan urlSpan : urls) {
        int start = spannableStringBuilder.getSpanStart(urlSpan);
        int end = spannableStringBuilder.getSpanEnd(urlSpan);
        int flags = spannableStringBuilder.getSpanFlags(urlSpan);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL()));
                context.startActivity(intent);
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setUnderlineText(false);
            }
        };
        spannableStringBuilder.removeSpan(urlSpan);
        spannableStringBuilder.setSpan(clickable, start, end, flags);
    }
    textView.setText(spannableStringBuilder);
}