Java Code Examples for android.widget.EditText#getText()

The following examples show how to use android.widget.EditText#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: EditorFragment.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
private void markdownNumberedList() {
    final EditText et = mContentET;
    Editable editable = et.getText();
    int start = et.getSelectionStart();
    String list = String.format(NUM_LIST, mListIndex);
    int diff = list.length();
    if (et.hasSelection()) {
        int end = et.getSelectionEnd();
        editable.insert(end, ENTER);
        editable.insert(start, list);
        et.setSelection(start + diff, end + diff);
    } else {
        editable.insert(start, list);
        et.setSelection(start + diff);
    }
}
 
Example 2
Source File: CreditCardValidatorProd.java    From CreditCardView with MIT License 6 votes vote down vote up
@Override
public boolean validateExpiredDate(EditText creditCardExpiredDate, boolean update) {

    String expiredDate;
    boolean validExpiredDate = false;

    if (creditCardExpiredDate.getText() != null && !TextUtils.isEmpty(
            expiredDate = creditCardExpiredDate.getText().toString())) {

        expiredDate = expiredDate.trim().replace(" ", "");
        if ((validExpiredDate = isValidExpiredDate(expiredDate)) && update) {
            creditCardExpiredDate.setText(expiredDate);
        }
    }

    return validExpiredDate;

}
 
Example 3
Source File: MainActivity.java    From testing-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the user wants to append an entry to the history.
 */
public void updateHistory(View view) {
    // Get the text to add and timestamp.
    EditText editText = (EditText) view.getRootView().findViewById(R.id.editText);
    CharSequence textToAdd = editText.getText();
    long timestamp = System.currentTimeMillis();

    // Show it back to the user.
    appendEntryToView(textToAdd.toString(), timestamp);

    // Update the history.
    mLogHistory.addEntry(textToAdd.toString(), timestamp);

    // Reset the EditText.
    editText.setText("");
}
 
Example 4
Source File: ValidatingTextInputLayout.java    From validator with Apache License 2.0 6 votes vote down vote up
/**
 * Invoke this when you want to validate the contained {@code EditText} input text against the
 * provided {@link Validator}. For validating multiple {@code ValidatingTextInputLayout}
 * objects at once, call {@link Validators#validate(ValidatingTextInputLayout...)}. Throws an
 * {@code IllegalStateException} if either no validator has been set or an error is triggered
 * and no error label is set.
 */
public boolean validate() {
    if (validator == null) {
        throw new IllegalStateException("A Validator must be set; call setValidator first.");
    }

    CharSequence input = "";
    EditText editText = getEditText();
    if (editText != null) {
        input = editText.getText();
    }

    boolean valid = validator.isValid(input.toString());
    if (valid) {
        setError(null);
    } else {
        if (errorLabel == null) {
            throw new IllegalStateException("An error label must be set when validating an " +
                    "invalid input; call setErrorLabel or app:errorLabel first.");
        }
        setError(errorLabel);
    }

    return valid;
}
 
Example 5
Source File: MainActivity.java    From WhatsApp-Direct-Message with MIT License 6 votes vote down vote up
public void SaveContact(View v) {

        EditText phoneNumberField = (EditText) findViewById(R.id.inputField);
        if (phoneNumberField.getText().toString().isEmpty()) {
            Alert_Dialog_Blank_Input();
        } else {
            Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
            intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
            mPhoneNumber = (EditText) findViewById(R.id.inputField);

            CountryCodePicker cpp = (CountryCodePicker) findViewById(R.id.cpp);
            String mNo = cpp.getFullNumberWithPlus() + mPhoneNumber.getText();
            intent.putExtra(ContactsContract.Intents.Insert.PHONE, mNo);

            startActivity(intent);
        }

    }
 
Example 6
Source File: WhatsappViewCompat.java    From WhatsappFormatter with Apache License 2.0 5 votes vote down vote up
/**
 * Performs formatting.
 */
private static void format(EditText editText, TextWatcher mainWatcher, TextWatcher[] otherWatchers ) {

    Editable text = editText.getText();
    CharSequence formatted = WhatsappViewCompat.extractFlagsForEditText(text);
    removeTextChangedListener(editText,mainWatcher);
    int selectionEnd = editText.getSelectionEnd();
    int selectionStart = editText.getSelectionStart();
    editText.setText(formatted);
    editText.setSelection(selectionStart, selectionEnd);
    Editable formattedEditableText = editText.getText();
    sendAfterTextChanged(otherWatchers, formattedEditableText);
    addTextChangedListener(editText, mainWatcher);
}
 
Example 7
Source File: EditorFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private void markdownCode() {
    final EditText et = mContentET;
    Editable editable = et.getText();
    int start = et.getSelectionStart();
    if (et.hasSelection()) {
        int end = et.getSelectionEnd();
        editable.insert(end, CODE);
        editable.insert(start, CODE);
        et.setSelection(start + 1, end + 1);
    } else {
        editable.insert(start, CODE2);
        et.setSelection(start + 1);
    }
}
 
Example 8
Source File: ViewEnablingTextWatcher.java    From Inside_Android_Testing with Apache License 2.0 5 votes vote down vote up
private void setViewEnabledState() {
    boolean enabledState = true;
    for (EditText editText : toWatch) {
        CharSequence text = editText.getText();
        if (text == null || text.toString().trim().length() == 0) {
            enabledState = false;
            break;
        }
    }
    toEnable.setEnabled(enabledState);
}
 
Example 9
Source File: SettingFragment.java    From CodePolitan with Apache License 2.0 5 votes vote down vote up
private void onSendFeedBack(EditText feedback)
{
    if (feedback.getText() == null || "".equals(feedback.getText().toString()))
    {
        feedback.setError("Please write your feedback here!");
    } else
    {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:[email protected]"));
        intent.putExtra(Intent.EXTRA_SUBJECT, "CodePolitan Feedback");
        intent.putExtra(Intent.EXTRA_TEXT, feedback.getText() + "\n\nSent from CodePolitan Apps.");
        startActivity(intent);
    }
}
 
Example 10
Source File: EditorFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private void markdownLink() {
    final EditText et = mContentET;
    Editable editable = et.getText();
    mLinkSelection = new Selection(et);
    CharSequence des = null;
    if (!mLinkSelection.isEmpty()) {
        des = editable.subSequence(mLinkSelection.start, mLinkSelection.end);
    }
    AddLinkFragment.newInstance(des).show(getChildFragmentManager(), "add_link_tag");
}
 
Example 11
Source File: EditorFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private void markdownUpload() {
    final EditText et = mContentET;
    Editable editable = et.getText();
    mUploadSelection = new Selection(et);
    CharSequence des = null;
    if (!mUploadSelection.isEmpty()) {
        des = editable.subSequence(mUploadSelection.start, mUploadSelection.end);
    }
    AddLinkFragment.newInstance(des, AddLinkFragment.MD_IMG).show(getChildFragmentManager(), "add_link_tag");
}
 
Example 12
Source File: WeakNetworkFragment.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
private long getLongValue(EditText editText) {
    CharSequence text = editText.getText();
    if (TextUtils.isEmpty(text)) {
        return 0L;
    }
    return Long.parseLong(text.toString());
}
 
Example 13
Source File: MainActivity.java    From Just-Java with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    // Get user's name
    EditText nameField = (EditText) findViewById(R.id.name_field);
    Editable nameEditable = nameField.getText();
    String name = nameEditable.toString();

    // Figure out if the user wants whipped cream topping
    CheckBox whippedCreamCheckBox = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
    boolean hasWhippedCream = whippedCreamCheckBox.isChecked();

    // Figure out if the user wants choclate topping
    CheckBox chocolateCheckBox = (CheckBox) findViewById(R.id.chocolate_checkbox);
    boolean hasChocolate = chocolateCheckBox.isChecked();

    // Calculate the price
    int price = calculatePrice(hasWhippedCream, hasChocolate);

    // Display the order summary on the screen
    String message = createOrderSummary(name, price, hasWhippedCream, hasChocolate);

    // Use an intent to launch an email app.
    // Send the order summary in the email body.
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_SUBJECT,
            getString(R.string.order_summary_email_subject, name));
    intent.putExtra(Intent.EXTRA_TEXT, message);

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}
 
Example 14
Source File: AMapUtil.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 判断edittext是否null
 */
public static String checkEditText(EditText editText) {
	if (editText != null && editText.getText() != null
			&& !(editText.getText().toString().trim().equals(""))) {
		return editText.getText().toString().trim();
	} else {
		return "";
	}
}
 
Example 15
Source File: PassphrasePromptActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private char[] getEnteredPassphrase(final EditText editText) {
  int len = editText.length();
  char[] passphrase = new char[len];
  if (editText.getText() != null) {
    editText.getText().getChars(0, len, passphrase, 0);
  }
  return passphrase;
}
 
Example 16
Source File: CreditCardValidatorProd.java    From CreditCardView with MIT License 4 votes vote down vote up
@Override
public boolean validateSecurityCode(IssuerCode issuerCode, EditText creditCardSecurityCode, boolean update) {

    String value;
    boolean result = false;

    if (creditCardSecurityCode.getText() != null && !TextUtils.isEmpty(
            value = creditCardSecurityCode.getText().toString())) {

        value = value.trim().replace(" ", "");

        int minDigits = issuerCode == IssuerCode.AMEX ? 4 : 3;

        if ((result = value.length() == minDigits && TextUtils.isDigitsOnly(value)) && update) {
            creditCardSecurityCode.setText(value);
        }
    }

    return result;

}
 
Example 17
Source File: VMEditor.java    From VMLibrary with Apache License 2.0 4 votes vote down vote up
public VMEditor(@NonNull EditText editText) {
    CheckNull(editText, "EditText不能为空");
    this.editable = editText.getText();
    this.editText = editText;
    editText.addTextChangedListener(new Watcher());
}
 
Example 18
Source File: BlockEditText.java    From BlockEditText with Apache License 2.0 4 votes vote down vote up
Editable getText(EditText editText) {
    return editText.getText();
}
 
Example 19
Source File: PerformEdit.java    From AndroidEdit with Apache License 2.0 4 votes vote down vote up
public PerformEdit(@NonNull EditText editText) {
    CheckNull(editText, "EditText不能为空");
    this.editable = editText.getText();
    this.editText = editText;
    editText.addTextChangedListener(new Watcher());
}
 
Example 20
Source File: Util.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isEmpty(EditText value) {
  return value == null || value.getText() == null || TextUtils.isEmpty(value.getText().toString());
}