List of usage examples for android.widget EditText.OnEditorActionListener EditText.OnEditorActionListener
EditText.OnEditorActionListener
From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java
protected void addEditListeners() { login.setEnabled(validateInput());/*from w ww .java2 s . c o m*/ username.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { login.setEnabled(validateInput()); } }); username.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && username.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "User name must contain at least " + MIN_USERNAME_LENGTH + " characters"; Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); password.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { login.setEnabled(validateInput()); } }); password.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && password.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "Password must contain at least " + MIN_PASSWORD_LENGTH + " characters"; Toast.makeText(getSherlockActivity(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); }