0

当焦点改变时,我正在使用以下代码显示编辑框的键盘。

  no1.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
            if(keyCode == 66) {

                no2.requestFocus();

            }
            }
            return false;
        }
    });


    no2.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
            if(keyCode == 66) {
                 //Log.e("I am inside no2","no2");
                no3.requestFocus();

                return true;


            }
            }
            return false;
        }
    });



    no2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
               Log.e("In","Innnnnn");
               InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(no2, InputMethodManager.SHOW_IMPLICIT);         
            }
        }
    });

但是键盘不显示。正在打印日志语句。这意味着它正在进入 focusChanged 方法。任何想法我做错了什么?

4

3 回答 3

0

使用 InputMethodManager 控制键盘。

于 2012-09-19T05:52:49.707 回答
0

尝试这个...

final AlertDialog dialog = ...;

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});
于 2012-09-19T06:04:14.313 回答
0

尝试这个

InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
于 2012-09-19T08:18:28.607 回答