Well, I tried all the solutions that I could find in stackoverflow and elsewhere, but the end result has not changed a single bit: the only key that fires the onKey or dispatchKeyEvent event is the enter key on the virtual keyboard, and only if you double-click . I cannot intercept any other key (there the breakpoint at the top of the event and the eclipse never stop at it, except that in the case of the above input). Beheavor is the same both on the emulator and on the real device. Any ideas? thanks in advance My atm code is as follows:
public class ChatWindow {
@Override
public void onCreate(Bundle savedInstanceState) {
setSendText();
}
private void setUserInput() {
Intent i = getIntent();
mChatInput = (EditText) findViewById(R.id.UsrInput);
if (i.hasExtra(INTENT_EXTRA_MESSAGE)) {
mChatInput.setText(i.getExtras().getString(INTENT_EXTRA_MESSAGE));
}
mChatInput.setFocusable(true);
mChatInput.requestFocus();
mChatInput.setFocusableInTouchMode(true);
mChatInput.addTextChangedListener(new TextWatcher() {
public void afterTextChanged (Editable s){
Log.d(TAG, "afterTextChanged");
if (mChatInput.getText().length() >= 1) {
mChatInput.addTextChangedListener(this);
mSendButton.setEnabled(true);
}
else
mSendButton.setEnabled(false);
}
public void beforeTextChanged (CharSequence s, int start, int
count, int after)
{
Log.d(TAG, "beforeTextChanged");
}
public void onTextChanged (CharSequence s, int start, int before,
int count)
{
Log.d(TAG, s.toString());
}
});
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode()==KeyEvent.KEYCODE_ENTER) {
sendMessageIfNotNull();
return true;
}
return false;
}
source
share