List of usage examples for android.widget TextView setError
@android.view.RemotableViewMethod public void setError(CharSequence error)
From source file:Main.java
/** * Set an error message to a text view/*from w ww .java 2 s .c o m*/ * * @param color Set the color foreground for the span * @param message Message to be shown * @param txtView Text View to which the message will be added */ public static void setError(int color, String message, TextView txtView) { ForegroundColorSpan fgcspan = new ForegroundColorSpan(color); SpannableStringBuilder ssbuilder = new SpannableStringBuilder(message); ssbuilder.setSpan(fgcspan, 0, message.length(), 0); txtView.setError(ssbuilder); }
From source file:de.spiritcroc.modular_remote.Util.java
/** * @return//w ww . ja v a 2s . c o m * Size if valid, else -1 */ public static double getSizeInput(TextView textView) { String input = textView.getText().toString(); if (input.equals("")) { Context context = textView.getContext(); textView.setError(context.getString(R.string.error_should_not_be_empty)); return -1; } try { double result = Double.parseDouble(input); if (result > 0) { return result; } else { Context context = textView.getContext(); textView.setError(context.getString(R.string.error_should_be_higher_than_zero)); return -1; } } catch (Exception e) { Context context = textView.getContext(); textView.setError(context.getString(R.string.error_invalid)); return -1; } }
From source file:de.spiritcroc.modular_remote.Util.java
/** * @return//from w w w. j a v a 2s .c om * User input if input allowed. null if invalid */ public static String getUserInput(TextView textView, boolean emptyForbidden) { String input = textView.getText().toString(); if (input.equals("")) { if (emptyForbidden) { Context context = textView.getContext(); textView.setError(context.getString(R.string.error_should_not_be_empty)); return null; } else { return input; } } for (String forbidden : FORBIDDEN_SUBSTRINGS) { if (input.contains(forbidden)) { Context context = textView.getContext(); String errorMsg = context.getString(R.string.error_should_not_contain_s, forbidden); textView.setError(errorMsg); return null; } } return input; }
From source file:org.jboss.aerogear.unifiedpush.quickstart.activities.ContactActivity.java
private boolean isValidForm() { boolean valid = true; List<EditText> componentsToValidate = Arrays.asList(firstName, lastName, phone, email, birthDate); for (TextView textView : componentsToValidate) { if (textView.getText().toString().length() < 1) { textView.setError("Can not be blank"); valid = false;//from ww w . j ava 2 s . co m } } return valid; }
From source file:pt.unl.fct.di.novalincs.yanux.scavenger.dialog.logging.LogDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); builder.setTitle(R.string.log_settings); // Inflate and set the layout for the alertDialog // Pass null as the parent view because its going in the alertDialog layout final View view = inflater.inflate(R.layout.fragment_log_dialog, null); logNameEditText = (EditText) view.findViewById(R.id.log_name); logSamplesEditText = (EditText) view.findViewById(R.id.log_samples); preferences = new Preferences(getActivity()); logNameEditText.setText(preferences.getLogName()); logSamplesEditText.setText(Integer.toString(preferences.getLogSamples())); builder.setView(view).setPositiveButton(R.string.start, new DialogInterface.OnClickListener() { @Override/* w w w.j a v a 2s. c o m*/ public void onClick(DialogInterface dialog, int id) { String logNameInput = logNameEditText.getText().toString().trim(); String logSamplesInput = logSamplesEditText.getText().toString().trim(); setLogName(logNameInput); setSamples(Integer.parseInt(logSamplesInput)); preferences.setLogName(getLogName()); preferences.setLogSamples(getSamples()); listener.onDialogPositiveClick(LogDialogFragment.this); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { listener.onDialogNegativeClick(LogDialogFragment.this); } }); alertDialog = builder.create(); logNameEditText.addTextChangedListener(new TextValidator(logNameEditText) { @Override public void validate(TextView textView, String text) { validateDialog(); if (!isValid() && text.trim().isEmpty()) { textView.setError(getActivity().getString(R.string.required)); } } }); logSamplesEditText.addTextChangedListener(new TextValidator(logSamplesEditText) { @Override public void validate(TextView textView, String text) { validateDialog(); if (!isValid() && text.trim().isEmpty()) { textView.setError(getActivity().getString(R.string.required)); } } }); return alertDialog; }
From source file:com.liuwei1995.red.fragment.presenter.EyeFragmentPresenter.java
private void showRedSnackbar() { if (redSnackbar == null) { synchronized (this) { if (redSnackbar == null) redSnackbar = new RedSnackbar(rv_content.getContext(), R.layout.snackbar_eye_activity_submit) { @Override/* ww w .j ava 2s . c o m*/ public void setCustomView(Context mContext, View customView) { setText(R.id.actv_license_plate_number, actv_license_plate_number.getText().toString()); setOnClickListener(R.id.btn_submit); } @Override public void onClick(View v) { AutoCompleteTextView tv_number = getView(R.id.actv_license_plate_number); String account = tv_number.getText().toString().trim(); if (TextUtils.isEmpty(account) || account.length() < 4) { tv_number.setError("???"); return; } AutoCompleteTextView tv_number_password = getView( R.id.actv_license_plate_numbed_password); String accountPassword = tv_number_password.getText().toString().trim(); if (TextUtils.isEmpty(accountPassword) || accountPassword.length() != 4) { tv_number_password.setError("???"); return; } dismiss(); OFOEntity item = new OFOEntity(); item.setAccount(account); item.setPhoneNumber(PhoneUtils.getPhoneNumber(mContext)); String androidID = DeviceUtils.getAndroidID(); item.setAndroidID(androidID); item.setIMEI(PhoneUtils.getIMEI()); item.setAccountPassword(accountPassword); item.setVersionName(BaseApplication.versionName); item.setVersionCode(BaseApplication.versionCode); submit(item); } }; } } else { TextView view = redSnackbar.getView(R.id.actv_license_plate_number); view.setError(null); view.setText(actv_license_plate_number.getText()); } redSnackbar.make(rv_content, 60 * 60 * 1000); }
From source file:com.ntsync.android.sync.activities.ImportActivity.java
public void onCreateEnd(boolean success, boolean cancel, ImportError error, int importedCount, int availableEnd) { if (success) { finish();/* w w w. j a v a 2 s . co m*/ } else { TextView textView = (TextView) findViewById(R.id.message_bottom); if (!cancel && error != null) { int msgId; switch (error) { case DB_ERROR: msgId = R.string.import_activity_dberror; break; default: msgId = R.string.import_activity_failed; break; } textView.setVisibility(View.VISIBLE); textView.setText(getText(msgId)); } else { textView.setVisibility(View.GONE); } if (textView.getVisibility() == View.VISIBLE) { textView.setError(getText(R.string.import_activity_retry)); } else { textView.setError(null); } } }
From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java
@Override public void onTimeSelected(long millis) { if (getActivity() == null) return;/*from ww w . j a va2s. co m*/ TextView tv = null; if (mLastTimeSelected == LastTimeSelected.START) tv = mStartTime; else if (mLastTimeSelected == LastTimeSelected.END) tv = mEndTime; else return; //O no! This should never happen! tv.setTag(millis); int flags = DateUtils.FORMAT_SHOW_TIME; if (DateFormat.is24HourFormat(getActivity())) flags |= DateUtils.FORMAT_24HOUR; else flags |= DateUtils.FORMAT_12HOUR; tv.setError(null); tv.setText(DateUtils.formatDateRange(getActivity(), millis, millis, flags)); }