Password verification as soon as the user enters the last digit
I have this login page as the second page of my application. there are 4 edit textboxes there.
i want that as soon as the user enters a digit in the fourth box then without doing anything the validation is done in the activity.
Right now i have managed to put onFocusChangeListener() but it reqires focus to be changes.
But my requirement is as soon as the user enter the value int hte fourth box without doing anything the validation should happen. my code is here.
fourthBox.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
EditText firstBox=(EditText)findViewById(R.id.passCode1);
EditText secondBox=(EditText)findViewById(R.id.passCode2);
EditText thirdBox=(EditText)findViewById(R.id.passCode3);
EditText fourthBox=(EditText)findViewById(R.id.passCode4);
String firstBoxValue = firstBox.getText().toString();
String secondBoxValue = secondBox.getText().toString();
String thirdBoxValue = thirdBox.getText().toString();
String fourthBoxValue = fourthBox.getText().toString();
if((firstBoxValue.length()==0) || (second开发者_开发百科BoxValue.length()==0) ||
(thirdBoxValue.length()==0) || (fourthBoxValue.length()==0))
{
Toast.makeText(present.this,"Enter all four Passcodes",Toast.LENGTH_SHORT).show();
}
You can use TextWatcher.
To get an event for every keystroke...
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s,
int start,
int count,
int after) {
}
public void onTextChanged(CharSequence s,
int start,
int before,
int count) {
}
public void afterTextChanged(Editable s) {
}
}
and
et.addTextChangedListener(textWatcher);
try this:
fourthBox.setOnClickListener(new EditText.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
The above idea is not good to do such task.You should give user button or something else to start your verification..
精彩评论