按下按钮时的 Android 输入验证并在对话框中显示验证消息,如下所示。
Codename is required
Password is required
USername is required.
Enter the valid Email id.
Dismiss
这是我的代码:
btninsert = (Button)findViewById(R.id.new_customer);
btninsert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText Firstname = (EditText) findViewById(R.id.tf_userName);
EditText Lastname = (EditText) findViewById(R.id.tf_password);
EditText Baddress = (EditText) findViewById(R.id.tf_address);
if(Firstname.getText().toString().length() == 0 )
Firstname.setError( "Firstname is required!" );
else if(Lastname.getText().toString().length() == 0 )
Lastname.setError( "Lastname is required!" );
else if(Baddress.getText().toString().length() == 0 )
Baddress.setError( "Address is required!" );
else
insertValues();
}
});
我该如何验证。