机器人组隐藏在$ P $的PSS连接时,键盘输入(在EditText上) [英] android set hidden the keybord on press enter (in a EditText)

查看:103
本文介绍了机器人组隐藏在$ P $的PSS连接时,键盘输入(在EditText上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用户preSS <大骨节病>输入上的虚拟机器人用户验证入口!时,键盘连接时,键盘我保持可见! (为什么?)

When my user press Enter on the virtual android "user validate entry!" keybord my keybord stay visible ! (Why?)

下面我的Java code ...

Here my Java code...

private void initTextField() {
    entryUser = (EditText) findViewById(R.id.studentEntrySalary);
    entryUser.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_DPAD_CENTER:
                    case KeyEvent.KEYCODE_ENTER:
                        userValidateEntry();
                        return true;
                }
            }

          return true;
        }
    });
}

private void userValidateEntry() {
    System.out.println("user validate entry!");
}

...在这里我查看

... here my View

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <EditText android:id="@+id/studentEntrySalary" android:text="Foo" android:layout_width="wrap_content" android:layout_height="wrap_content" />
 </LinearLayout>

也许我的虚拟设备上什么事吗?

Maybe something wrong on my virtual device ?

删除死ImageShack链接

推荐答案

这应该做到这一点:

yourEditTextHere.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

                // NOTE: In the author's example, he uses an identifier
                // called searchBar. If setting this code on your EditText
                // then use v.getWindowToken() as a reference to your 
                // EditText is passed into this callback as a TextView

                in.hideSoftInputFromWindow(searchBar
                        .getApplicationWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
               userValidateEntry();
               // Must return true here to consume event
               return true;

            }
            return false;
        }
    });

这篇关于机器人组隐藏在$ P $的PSS连接时,键盘输入(在EditText上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆