I am trying to use the same EDITTEXT controller to get password and confirmpassword and this is the code that I am using.
public class MainActivity extends Activity {
protected Button SignupButton;
protected EditText NameSignup,EmailSignup,PasswordSignup;
String passwordInitial;
int Inte = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize
SignupButton = (Button)findViewById(R.id.signupButtonSignup);
NameSignup = (EditText)findViewById(R.id.nameSignup);
EmailSignup = (EditText)findViewById(R.id.emailSignup);
PasswordSignup = (EditText)findViewById(R.id.passwordSignup);
PasswordSignup.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) {
if (0 >= Inte){
//you require to put validations you want
passwordInitial = PasswordSignup.getText().toString();
PasswordSignup.setText(null);
PasswordSignup.setHint("Confirm Password");
PasswordSignup.requestFocus();
Inte++;
}else {
Inte--;
return;
}
}
}
});
But the problem that I am facing is when the user enters the password for the first time and the edittext looses focus, the focus is coming back to the password field which is what I want, BUT the problem is to LOOSE FOCUS i have to choose ANOTHER FIELD and then when the keyboard popsup whatever I enter is in the EDITTEXT field that I have CHOOSEN to loose focus and NOT the password field. What I can do to make this feature happen as smoothly as possible.
EDIT: More detailed explanation
In normal signup forms/activity you have a filed/s to double confirm your password. One is you type the passwod and again the other time to confirm that you have typed the correct password as you want, this is pretty self explanatory. In my application I want to make these two in to only one EDITTEXT controller, SO which means once the user types in the password for the first time AND loose focus, i want to bring the focus back to the same EDITTEXT controller and ask him to type the confirmpassword, so once he does that and when he presses the signup button in my activity then I will check if the password typed the first time and the second time matches and proceed to signup. Hope this is clear enough (this is the part i am not sure how to capture how to loose focus once he finishes the typing of password the second time)