Android setOnKeyListener in Dialog

It took me a few tries to get the onKeyListener to work on a dialog EditText. The key is to use View.OnKeyListener() instead of just OnKeyListener().

Here is the code:

		final Dialog newReminderDialog = new Dialog(getActivity());
		newReminderDialog.setTitle("Set Time");;
		EditText addToTimeEditText = (EditText) newReminderDialog.findViewById(;
		addToTimeEditText.setOnKeyListener(new View.OnKeyListener(){
			public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
				// TODO Auto-generated method stub
				Toast.makeText(getActivity(), "t", Toast.LENGTH_SHORT).show();
				return true;
Tagged , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: