editText field is required before moving on to another Activity

后端 未结 7 1310
情深已故
情深已故 2021-01-30 17:14

I have validation for editText. If the editText field is empty it should fail validation and stop the user moving on to another Activity,

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 18:06

    I understand it's an old question but may this helps, you can use .isEmpty() instead of .equals()

    if( userName.getText().toString().isEmpty()){
    
       /**
        *   You can Toast a message here that the Username is Empty    
        **/
    
       userName.setError( "First name is required!" );
    
    }else{
       Intent i = new Intent(getApplicationContext(), Login.class);
       startActivity(i);
    }
    

提交回复
热议问题