0

I'm having a problem with the keylistener on my android app. When testing on the emulator, it works great, but after exporting the APK and trying on my real device, it doesn't work anymore.

I saw a similar question here but the answer didn't helped me. It was telling me to add setFocusable(true); and setFocusableInTouchMode(true); to my code, but it didn't worked. (I assumed I should add this to my editView)

The code is this:

edtText.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if(edtText.getText().length()>0 && edtText.getText().length()<141){
                btnEnviar.setEnabled(true);
            }
            else{
                lblNumeroCaracteres.setTextColor(Color.RED);
                btnEnviar.setEnabled(false);
            }
            lblNumeroCaracteres.setText(String.valueOf(edtText.getText().length()));
            return false;
        }
     });

Does anyone knows how to fix this problem?

Thanks in advice!

4

1 回答 1

0

尝试使用

addTextChangedListener(TextWatcher watcher) 

在这里定义 它,您可以处理物理键盘和软键盘。我希望它有帮助

于 2012-12-16T16:47:17.003 回答