Java Code Examples for android.support.design.widget.TextInputEditText#getText()

The following examples show how to use android.support.design.widget.TextInputEditText#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayerBindingAdapters.java    From spline with Apache License 2.0 5 votes vote down vote up
/**
 * Binding adapter for converting view position and dimension values to text for EditTexts. The
 * InverseBindingAdapter that follows does the reverse
 * @param view
 * @param dimValue
 */
@BindingAdapter("android:text")
public static void setText(TextInputEditText view, float dimValue) {
    String curString = view.getText().toString();
    int curInt;
    try {
        curInt = Integer.parseInt(curString);
    } catch (NumberFormatException e) {
        curInt = 0;
    }

    // Do not set the text if the parsed string is null, if it ends in a . or if it is equal to
    // the current value to avoid the value changing under the user's cursor (and the cursor
    // jumping) as they type.
    if (curString == null
            || curString.length() == 0
            || curString.charAt(curString.length() - 1) != '.'
            && dimValue != curInt) {

        String dimString = "";
        if (dimValue == (int) dimValue) {
            dimString = Integer.toString((int) dimValue);
        } else {
            dimString = Float.toString(dimValue);
        }

        if (dimString != null && view != null && view.getText() != null &&
                !dimString.equals(view.getText().toString())) {
            view.setText(dimString);
        }
    }
}
 
Example 2
Source File: SharedPrefManagerActivity.java    From SharedPrefManager with Apache License 2.0 4 votes vote down vote up
@NonNull
private String getTextFrom(TextInputEditText textInputEditText) {
    Editable editable = textInputEditText.getText();
    return editable == null ? "" : editable.toString();
}