editText field is required before moving on to another Activity

后端 未结 7 1313
情深已故
情深已故 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 17:55

    Try this:

    bt.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0)
        {
            String  str=et.getText().toString();
    
            if(str.equalsIgnoreCase(""))
            {
                et.setHint("please enter username");//it gives user to hint
                et.setError("please enter username");//it gives user to info message //use any one //
            }
            else
            {
                Intent in=new Intent(getApplicationContext(),second.class);
                startActivity(in);
            }
        }
    });
    

提交回复
热议问题