Android setError(“error”) not working in Textview

前端 未结 4 381
醉酒成梦
醉酒成梦 2020-12-09 08:30

We can set error in Edittext successfully but failed to set in textview. is there any problem?? i tried

((TextView) findViewById(R.id.df)).requestFocus();
((         


        
4条回答
  •  醉话见心
    2020-12-09 08:32

    Snippet: you have to requestFocus(); a view to show the error.

        // 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();
        }
        });
    }
    

提交回复
热议问题