Code example for EditText

Methods: setOnKeyListenergetTextaddTextChangedListenersetOnEditorActionListener

0
	private void updateEnablement() { 
		connect.setEnabled(loginEnabled());
	} 
 
	private boolean loginEnabled() { 
		return login.getText().length() > 0 && password.getText().length() > 0;
	} 
 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getSupportActionBar().setDisplayShowTitleEnabled(false); 
		getSupportActionBar().setDisplayShowHomeEnabled(false); 
 
		UpdateUiTextWatcher watcher = new UpdateUiTextWatcher();
		login.addTextChangedListener(watcher);
		password.addTextChangedListener(watcher);
 
		signupLink.setMovementMethod(LinkMovementMethod.getInstance());
 
		updateEnablement(); 
 
		password.setOnKeyListener(new View.OnKeyListener() {
 
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event != null && ACTION_DOWN == event.getAction()
						&& keyCode == KEYCODE_ENTER && loginEnabled()) {
					handleLogin(); 
					return true; 
				} else 
					return false; 
			} 
		}); 
 
		password.setOnEditorActionListener(new OnEditorActionListener() {
 
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				if (actionId == IME_ACTION_DONE && loginEnabled()) {
					handleLogin();