Android setError ( "ошибка" ) не работает в Textview
Мы можем установить ошибку в Edittext успешно, но не удалось установить в textview. есть какие-либо проблемы??
я попробовал
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setSelected(true);
((TextView) findViewById(R.id.df)).setError("akjshbd");
но я не получаю всплывающее окно для ошибки.
![Textview Error]()
Ответы
Ответ 1
Собственно, вы можете использовать setError для textView и показывать его всплывающее окно.
Вам просто нужно использовать тот же стиль, что и в EditText.
Просто добавьте следующий атрибут для textView в xml:
style="@android:style/Widget.EditText"
Ответ 2
По умолчанию TextView НЕ настраивается. Итак, вам нужно установить андроид: focusable = "true" и андроид: focusableInTouchMode = "true" .
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
И не нужно устанавливать setSelected (true).
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setError("akjshbd");
Ответ 3
Это единственное, что вам нужно, чтобы получить ожидаемое поведение setError в TextView
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
Ответ 4
Фрагмент: вам нужно запроситьFocus(); чтобы показать ошибку.
// Check for a valid email address.
if (TextUtils.isEmpty(mEmail)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
} else if (!mEmail.contains("@")) {
mEmailView.setError(getString(R.string.error_invalid_email));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
// showProgress(true);
// mAuthTask = new UserLoginTask();
// mAuthTask.execute((Void) null);
ParseUser.logInInBackground(mEmail, mPassword, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
finishAndStartCardActivity();
}
});
}