簡體   English   中英

OnKeyListener()在三星Galaxy S3上不起作用

[英]OnKeyListener() not working on Samsung Galaxy S3

我在EditText上應用了OnKeyListener(),但它不能在Samsung Galaxy S3上使用,但在所有其他手機上都可以使用...不知道我在做什么錯...

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

        @Override
        public boolean onKey(View arg0, int keyCode, KeyEvent arg2) {
            // TODO Auto-generated method stub
            // You can identify which key pressed buy checking keyCode value
            // with KeyEvent.KEYCODE_
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                // this is for backspace
                Log.d("Button Event", "BackSpace Pressed");
                if (et.getSelectionStart() < length + 1) {
                    return true;
                } else {
                    return false;
                }
            }
            return false;
        }

    });

您可以嘗試使用et.addTextChangedListener(new TextWatcher()..)並將所有邏輯移至afterTextChanged(...)回調中。

View.OnKeyListener的description所述,OnKeyListener()僅通過硬件鍵盤上的事件調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM