开发者

Android 2.3 problem with EditText onKeyListener

I have an app made for the 1.6 version, and it works great till 2.2. Now I am making some updates and realize that onKeyListener won't work on 2.3, on previous versions is 开发者_如何学JAVAgood. Check this

etValue.setOnKeyListener(new View.OnKeyListener() {

                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // TODO Auto-generated method stub
                    return false;
                }
            });

etValue is EditText.


I checked this code on 2.3.1 its working Pls Try it

EditText ed=(EditText)findViewById(R.id.editText1);
ed.setOnKeyListener(new OnKeyListener() {

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "Done", 
            Toast.LENGTH_SHORT).show();
        return false;
    }
});


Are you using EditText in a dialog and you implement onShowListener on the dialog? This may have caused dialog to take away focus from the EditText field. Remove onShowListener for dialog. You may instead implement onFocusChanged for the EditText to determine kinda implicitly when the dialog is shown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜