开发者

sonyericsson xperia x10 del key

I open virtual keyboard and get pressed key in my 2d application. but virtual keyboard doesn't give any response when I pr开发者_JAVA百科ess DEL key on virtual keyboard.

How can I know when user press DEL key or can I add global keylistener to system?


The easiest way is create your own edit based on EditText widget:

public class CustomEditText extends EditText {
    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
}

Then, override the method OnKeyPreIme

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_DEL) {
        // Do something
    }
    return super.onKeyPreIme(keyCode, event);
}

Of course, above method works if you have an EditText for which on-screen keyboard is opened(but you can create one with the size of 0 dip, anyway)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜