Example usage for android.widget TextView getText

List of usage examples for android.widget TextView getText

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public CharSequence getText() 

Source Link

Document

Return the text that TextView is displaying.

Usage

From source file:org.deviceconnect.android.uiapp.fragment.profile.VibrationProfileFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View view = inflater.inflate(R.layout.fragment_vibration_service, container, false);
    view.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    final TextView pattern = (TextView) view.findViewById(R.id.fragment_vibration_pattern);

    Button btn = (Button) view.findViewById(R.id.fragment_vibration_send);
    btn.setOnClickListener(new OnClickListener() {
        @Override/*from   w  ww .j  a v a2s  .co  m*/
        public void onClick(final View v) {
            sendVibration(pattern.getText());
        }
    });
    return view;
}

From source file:com.google.reviewit.AddReviewerFragment.java

private void initInputField(final Change change) {
    AutoCompleteTextView editText = (AutoCompleteTextView) v(R.id.reviewerInput);
    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override//  w ww .j a  v  a 2s. c o  m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                addReviewer(change, v.getText().toString());
                handled = true;
            }
            return handled;
        }
    });
    editText.setAdapter(new SuggestReviewerAdapter(getContext()));
}

From source file:most.voip.example.remote_config.MainActivity.java

public void loadConfig(View view) {
    Log.d(TAG, "Called loadConfig");
    TextView txtAccount = (TextView) findViewById(R.id.txt_webserver_ip);
    serverIp = txtAccount.getText().toString();
    serverPort = 8000;//from w  ww.ja v  a2s.  c  o m

    Intent intent = getIntent();
    String ipAddress = intent.getStringExtra("ip_address");
    Log.d(TAG, "IpAddress: " + ipAddress);
    String accessToken = intent.getStringExtra("access_token");

    this.configServer = new ConfigServer(this, serverIp, serverPort, accessToken);

    Listener<JSONObject> listener = new Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Log.d(TAG, "Query Response::" + response);
            try {
                Log.d(TAG, "Accounts" + response.getJSONObject("data").getJSONArray("accounts"));
                accounts = response.getJSONObject("data").getJSONArray("accounts");
                updateAccountsArray();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e(TAG, "error:" + e);
            }

        }
    };
    ErrorListener errorListener = new ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError arg0) {
            // TODO Auto-generated method stub

        }
    };
    this.configServer.getAccounts(listener, errorListener);
}

From source file:com.hybris.mobile.adapter.CartAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Object cartItem = items.get(position);
    View rowView = null;//from  w  ww.ja va 2s . c  o  m

    if (cartItem instanceof CartEntry) {
        CartEntry cartEntry = (CartEntry) cartItem;

        rowView = inflater.inflate(R.layout.cart_row, parent, false);

        TextView lblProductTitle = (TextView) rowView.findViewById(R.id.lbl_product_title);
        TextView lblProductPrice = (TextView) rowView.findViewById(R.id.lbl_price_quantity);
        TextView lblManufacturer = (TextView) rowView.findViewById(R.id.lbl_productManufacturer);
        TextView lblTotal = (TextView) rowView.findViewById(R.id.lbl_total);
        ImageView productImage = (ImageView) rowView.findViewById(R.id.img_product);

        if (StringUtils.isEmpty(cartEntry.getProduct().getManufacturer())) {
            lblManufacturer.setHeight(0);
        } else {
            lblManufacturer.setText(cartEntry.getProduct().getManufacturer());
        }
        lblProductTitle.setText(cartEntry.getProduct().getName());
        lblProductPrice.setText(cartEntry.getBasePrice().getFormattedValue() + " - "
                + this.getContext().getString(R.string.cartentry_quantity_placeholder)
                + cartEntry.getQuantity().toString());
        lblManufacturer.setText(cartEntry.getProduct().getManufacturer());

        lblTotal.setText(cartEntry.getTotalPrice().getFormattedValue());
        UrlImageViewHelper.setUrlDrawable(productImage, cartEntry.getProduct().getThumbnail(),
                R.drawable.loading_drawable);
    }
    // Promotions
    else if (cartItem instanceof CartPromotion) {
        CartPromotion cartPromotion = (CartPromotion) cartItem;

        rowView = inflater.inflate(R.layout.promotion_row, parent, false);

        // Update promotions section
        TextView promotionsTextView = (TextView) rowView.findViewById(R.id.textView);
        promotionsTextView.setMovementMethod(LinkMovementMethod.getInstance());

        promotionsTextView.setText(Html.fromHtml(Cart.generatePromotionString(cartPromotion)));
        StringUtil.removeUnderlines((Spannable) promotionsTextView.getText());
    }

    return rowView;
}

From source file:com.QuarkLabs.BTCeClient.fragments.HistoryFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mAdapter = new OrdersAdapter(getActivity(), mHistoryType);
    mListView = (ListView) getView().findViewById(R.id.HistoryContainer);
    final EditText startDate = (EditText) getView().findViewById(R.id.StartDateValue);
    final EditText endDate = (EditText) getView().findViewById(R.id.EndDateValue);
    startDate.setText(mDateFormat.format(mStartDateValue));
    endDate.setText(mDateFormat.format(mEndDateValue));
    Button makeQuery = (Button) getView().findViewById(R.id.MakeQueryButton);
    View.OnClickListener showDatePicker = new View.OnClickListener() {
        @Override/*w  ww  .  ja  v a  2s. com*/
        public void onClick(View v) {
            final TextView dateValue = (TextView) v;
            Date date = null;
            try {
                date = mDateFormat.parse(dateValue.getText().toString());
            } catch (ParseException e) {
                e.printStackTrace();
            }
            int year = 1999;
            int month = 0;
            int day = 1;
            if (date != null) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                year = calendar.get(Calendar.YEAR);
                month = calendar.get(Calendar.MONTH);
                day = calendar.get(Calendar.DAY_OF_MONTH);
            }

            DatePickerDialog datePickerDialog = new android.app.DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Calendar calendar = Calendar.getInstance();
                            if (dateValue.getId() == R.id.StartDateValue) {
                                calendar.setTime(mStartDateValue);
                                calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0);
                                mStartDateValue = calendar.getTime();
                            } else {
                                calendar.setTime(mEndDateValue);
                                calendar.set(year, monthOfYear, dayOfMonth, 23, 59, 59);
                                mEndDateValue = calendar.getTime();
                            }
                            dateValue.setText(mDateFormat.format(calendar.getTime()));
                        }
                    }, year, month, day);
            datePickerDialog.getDatePicker().setCalendarViewShown(false);
            datePickerDialog.show();
        }
    };
    startDate.setOnClickListener(showDatePicker);
    endDate.setOnClickListener(showDatePicker);
    makeQuery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Bundle bundle = new Bundle();
            bundle.putString("startDate", String.valueOf(mStartDateValue.getTime() / 1000));
            bundle.putString("endDate", String.valueOf(mEndDateValue.getTime() / 1000));
            getLoaderManager().restartLoader(mLoaderId, bundle, HistoryFragment.this);
            mListView.setAdapter(null);
            mNoItems.setVisibility(View.GONE);
            mListView.setEmptyView(mLoadingView);

        }
    });
    mLoadingView = (ProgressBar) getView().findViewById(R.id.Loading);
    mNoItems = (TextView) getView().findViewById(R.id.NoItems);
    mListView.setEmptyView(mLoadingView);
}

From source file:arun.com.chameleonskinforkwlp.MainActivity.java

public void onFormulaClicked(View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        final CharSequence textToCopy = textView.getText();
        final ClipData clip = ClipData.newPlainText("formula", textToCopy);
        Snackbar.make(binding.coordinatorLayout, String.format(getString(R.string.copied_alert), textToCopy),
                Snackbar.LENGTH_SHORT).show();
        clipboard.setPrimaryClip(clip);//from  w ww  . j a  v a2  s .  com
    }
}

From source file:mad.codeforcommunity.CalendarView.java

public void loadEventView(View v) {
    TextView date = (TextView) v.findViewById(R.id.date);
    ImageView image = (ImageView) v.findViewById(R.id.date_icon);
    if (date instanceof TextView && !date.getText().equals("")) {
        if (image.getVisibility() == View.VISIBLE) {
            /*OLD CODE/*from  w  w  w .  j  a va2 s. com*/
             * Intent intent = new Intent();
            String day = date.getText().toString();
            if(day.length()==1) {
              day = "0"+day;
            }
            // return chosen date as string format 
            intent.putExtra("date", android.text.format.DateFormat.format("yyyy-MM", month)+"-"+day);
            setResult(RESULT_OK, intent);
            finish();
             */

            Bundle extras = new Bundle();
            String day = date.getText().toString();
            if (day.length() == 1) {
                day = "0" + day;
            }
            // return chosen date as string format 
            extras.putString("date", android.text.format.DateFormat.format("yyyy-MM", month) + "-" + day);

            Intent intent = new Intent(CalendarView.this, EventView.class);
            intent.putExtras(extras);

            startActivity(intent);
        }

    }
}

From source file:aleajactatest.appiumcalculator.CalculatorActivity.java

/**
 * Initializes the click listeners on the buttons
 *///from ww  w.ja  v  a  2 s  .  c o m
private void initButtonsClickListeners() {

    View.OnClickListener globalClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (v != null && !(v instanceof Button))
                    return;
                Button b = (Button) v;
                String val = b.getText().toString();
                TextView tvScore = (TextView) findViewById(R.id.tvScore);
                String text = tvScore.getText() + "";
                tvScore.setText(text + val);
                switch (val) {
                case "0":
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                    if (mOperation == Operation.NOPE) {
                        mLeftPart = Integer.parseInt(val);
                    } else {
                        mRightPart = Integer.parseInt(val);
                    }
                    break;
                case "+":
                    mOperation = Operation.ADD;
                    break;
                case "-":
                    mOperation = Operation.SUB;
                    break;
                case "/":
                    mOperation = Operation.DIV;
                    break;
                case "X":
                    mOperation = Operation.MULT;
                    break;
                case "=":
                    mScore = compute(mLeftPart, mOperation, mRightPart);
                    tvScore.setText(Double.toString(mScore));
                    break;
                case "Clean":
                default:
                    initDefaultValues();
                    break;
                }
            } catch (Exception e) {
                Log.e("CalculatorActivity", e.getMessage());
                TextView tvLog = (TextView) findViewById(R.id.tvLog);
                tvLog.setText(e.getMessage());
            }
        }
    };

    findViewById(R.id.button0).setOnClickListener(globalClickListener);
    findViewById(R.id.button1).setOnClickListener(globalClickListener);
    findViewById(R.id.button2).setOnClickListener(globalClickListener);
    findViewById(R.id.button3).setOnClickListener(globalClickListener);
    findViewById(R.id.button0).setOnClickListener(globalClickListener);
    findViewById(R.id.button5).setOnClickListener(globalClickListener);
    findViewById(R.id.button6).setOnClickListener(globalClickListener);
    findViewById(R.id.button7).setOnClickListener(globalClickListener);
    findViewById(R.id.button8).setOnClickListener(globalClickListener);
    findViewById(R.id.button9).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonAdd).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonDiv).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonSub).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonMul).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonEqual).setOnClickListener(globalClickListener);
    findViewById(R.id.buttonClean).setOnClickListener(globalClickListener);

}

From source file:com.fastbootmobile.encore.utils.Utils.java

/**
 * Calculates the optimal size of the text based on the text view width
 *
 * @param textView     The text view in which the text should fit
 * @param desiredWidth The desired final text width, or -1 for the TextView's getMeasuredWidth
 *//*from  w w w. j  ava  2 s . c  o m*/
public static void adjustTextSize(TextView textView, int desiredWidth) {
    if (desiredWidth <= 0) {
        desiredWidth = textView.getMeasuredWidth();

        if (desiredWidth <= 0) {
            // Invalid width, don't do anything
            Log.w("Utils", "adjustTextSize: Not doing anything (measured width invalid)");
            return;
        }
    }

    // Add some margin to width
    desiredWidth *= 0.8f;

    Paint paint = new Paint();
    Rect bounds = new Rect();

    paint.setTypeface(textView.getTypeface());
    float textSize = textView.getTextSize() * 2.0f;
    paint.setTextSize(textSize);
    String text = textView.getText().toString();
    paint.getTextBounds(text, 0, text.length(), bounds);

    while (bounds.width() > desiredWidth) {
        textSize--;
        paint.setTextSize(textSize);
        paint.getTextBounds(text, 0, text.length(), bounds);
    }

    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}

From source file:fr.cph.chicago.core.activity.BusActivity.java

/**
 * Draw arrivals in current main.java.fr.cph.chicago.res.layout
 *//*  w  w  w.  ja  v a2  s.c o  m*/
public void drawArrivals() {
    final Map<String, TextView> tempMap = new HashMap<>();
    if (busArrivals.size() != 0) {
        Stream.of(busArrivals).filter(arrival -> arrival.getRouteDirection().equals(bound)
                || arrival.getRouteDirection().equals(boundTitle)).forEach(arrival -> {
                    final String destination = arrival.getBusDestination();
                    final String arrivalText;
                    if (tempMap.containsKey(destination)) {
                        final TextView arrivalView = tempMap.get(destination);
                        arrivalText = arrival.isDly() ? arrivalView.getText() + " Delay"
                                : arrivalView.getText() + " " + arrival.getTimeLeft();
                        arrivalView.setText(arrivalText);
                    } else {
                        final TextView arrivalView = new TextView(getApplicationContext());
                        arrivalText = arrival.isDly() ? arrival.getBusDestination() + " Delay"
                                : arrival.getBusDestination() + " " + arrival.getTimeLeft();
                        arrivalView.setText(arrivalText);
                        arrivalView.setTextColor(grey);
                        tempMap.put(destination, arrivalView);
                    }
                });
    } else {
        final TextView arrivalView = new TextView(getApplicationContext());
        arrivalView.setTextColor(grey);
        arrivalView.setText(busActivityNoService);
        tempMap.put("", arrivalView);
    }
    stopsView.removeAllViews();
    Stream.of(tempMap.entrySet()).forEach(entry -> stopsView.addView(entry.getValue()));
}