Edittext ではエラーを設定できますが、textview では設定できませんでした。何か問題ある??私は試した
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setSelected(true);
((TextView) findViewById(R.id.df)).setError("akjshbd");
しかし、エラーのポップアップが表示されません。
Edittext ではエラーを設定できますが、textview では設定できませんでした。何か問題ある??私は試した
((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setSelected(true);
((TextView) findViewById(R.id.df)).setError("akjshbd");
しかし、エラーのポップアップが表示されません。
デフォルトの TextView はフォーカス可能ではありません。したがって、 android:focusable="true"とandroid: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");
実際には、textView に setError を使用して、そのポップアップを表示できます。
EditText と同じスタイルを使用するだけです。
xml に textView の次の属性を追加するだけです。
style="@android:style/Widget.EditText"
これは、TextView で予期される setError の動作を取得するために必要な唯一のものです。
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
スニペット: requestFocus(); が必要です。エラーを表示するビュー。
// 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();
}
});
}