Answers
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SignupActivity extends AppCompatActivity {
EditText editTextName,editTextEmail,editTextPhone,editTextPswd,editTextCPswd,editTextAge,editTextFatherName;
Button btnMoveToLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
editTextName=findViewById(R.id.editTextName);
editTextFatherName=findViewById(R.id.editTextFatherName);
editTextAge=findViewById(R.id.editTextAge);
editTextPhone=findViewById(R.id.editTextPhoneNumber);
editTextPswd=findViewById(R.id.editTextPswd);
editTextCPswd=findViewById(R.id.editTextCPswd);
editTextEmail=findViewById(R.id.editTextEmail);
btnMoveToLogin=findViewById(R.id.buttonMoveToLogIn);
btnMoveToLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Name",editTextEmail.getText().toString());
// if any of the text field is not populated , show toast message
// trim is used to remove trailing and leading spaces
// length is used to return the number of characters in the string
if(editTextEmail.getText().toString().trim().length() == 0 || editTextFatherName.getText().toString().trim().length() == 0 || editTextPhone.getText().toString().trim().length() == 0 || editTextPswd.getText().toString().trim().length() == 0 || editTextCPswd.getText().toString().trim().length() == 0 || editTextName.getText().toString().trim().length() == 0 ||
editTextAge.getText().toString().trim().length() == 0){
Toast.makeText(SignupActivity.this, "Please enter all the fields", Toast.LENGTH_SHORT).show();
}else{
// if passwords do not match, show toast message
if(!editTextCPswd.getText().toString().equals(editTextPswd.getText().toString()))
{
Toast.makeText(SignupActivity.this, "Passwords do not match!!", Toast.LENGTH_SHORT).show();
}else{
// All fields are populated and passwords match, hence proceed to the next activity
Intent intent=new Intent(SignupActivity.this, LoginActivity.class);
startActivity(intent);
}
}
}
});
}
}