硬键盘故障集中EDITTEXT故障、键盘、EDITTEXT

由网友(▓从此隐姓埋名丶)分享简介:我有一个共同的EditText。这是很奇怪的,因为当用硬键盘我不能集中了。背景情况:I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:切换Droi...

我有一个共同的EditText。这是很奇怪的,因为当用硬键盘我不能集中了。背景情况:

I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:

切换Droid的hardkeyboard上 启动活动 点击EDITTEXT输入 失败输入。当你preSS任何按键,EDITTEXT失去焦点。

要获得焦点: preSS使用Dpad,你会看到焦点开始从屏幕的第一个部件。最后重点目标的EditText。然后,您可以输入。没有这一点,你不能输入与硬键盘的。

To get focus: press Dpad and you will see the focus starts from the 1st widget in the screen. And finally focus on the target EditText. Then you can input. Without this, you can't input with hard keyboard at all.

软键盘上没有这样的焦点问题。

Soft keyboard doesn't have such focus problem.

我使用的Andr​​oid 2.2。这是一个系统错误吗?

I am using android 2.2. Is this a system bug?

推荐答案

正如上面提到的,这显然与硬键盘的错误。如果你有一个EditText和TabHost的布局,在第一个关键pressed,的EditText失去焦点和关键preSS被发送到活动代替。这是一个工作围绕这个问题。在您的活动实现这一点。

As mentioned above this is clearly a bug with hard keyboard. If you have an EditText and a TabHost in your layout, on first key pressed, EditText lose focus and key press is sent to the activity instead. Here is a work around to this problem. Implement this in your activity.

@Override

public boolean onKeyDown(int keyCode, KeyEvent event){

    final EditText myInputField = (EditText) findViewById(R.id.MyInputEditText);
    // this will happen on first key pressed on hard-keyboard only. Once myInputField 
    // gets the focus again, it will automatically receive further key presses.
    if (!myInputField.hasFocus()){ 
        myInputField.requestFocus();
        myInputField.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
}

如果您有多个领域的EditText,则需要跟踪当前集中的EditText在一个类变量,并使用它的onkeydown方法。

if you have multiple EditText fields, you will need to keep track of currently focused EditText in a class variable and use it in onKeyDown method.

阅读全文

相关推荐

最新文章