当我单击“完成”时,Android OnEditorActionListener() actionId 给出 0

发布于 2024-12-08 10:28:32 字数 1875 浏览 1 评论 0原文

我已经创建了一个键盘。当用户输入数字时,它们会被发送到特定的 EditText,但是当用户单击“完成”键时,它不会转到 setOnEditorActionListener(但它会关闭键盘)。

这是我的代码:

 final EditText txtQty = new EditText(this);
    txtQty.setHeight(1);
    txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
    txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
    txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
    txtQty.setSelectAllOnFocus(true);
    txtQty.setTextSize(9);
    txtQty.setVisibility(View.VISIBLE);
    txtQty.setHint("0.0");
    txtQty.setHighlightColor(R.color.green);
    tr.addView(txtQty);
    txtQty.setOnEditorActionListener( new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            Log.i("KeyBoard" ,"Inside the Edit Text");
            if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}

这里给出了 actionId = 0EditorInfo.IME_ACTION_NEXT = 5

当我通过 Android 软键盘运行时,它工作正常。

  txtQty.setOnEditorActionListener( new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            Log.i("KeyBoard" ,"Inside the Edit Text");
            Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
            Log.i("---actionId---" , actionId);
            Log.i("---event---" , event);
            Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);

这里给出了 EditorInfo.IME_ACTION_NEXT = 5, actionId = 5EditorInfo.IME_ACTION_DONE = 6, actionId = 6

但是当我通过软键盘运行时,它给出了 EditorInfo .IME_ACTION_NEXT = 5, actionId = 0EditorInfo.IME_ACTION_DONE = 6,actionId = 0

为什么它没有采用我的软键盘上的 actionId 值?

I have created a keyboard. When the user enters numbers they're sent to a particular EditText, but when the user clicks on the "Done" key it doesn't go to setOnEditorActionListener (but it does close the keyboard).

This is my code:

 final EditText txtQty = new EditText(this);
    txtQty.setHeight(1);
    txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
    txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
    txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
    txtQty.setSelectAllOnFocus(true);
    txtQty.setTextSize(9);
    txtQty.setVisibility(View.VISIBLE);
    txtQty.setHint("0.0");
    txtQty.setHighlightColor(R.color.green);
    tr.addView(txtQty);
    txtQty.setOnEditorActionListener( new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            Log.i("KeyBoard" ,"Inside the Edit Text");
            if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}

Here it gives actionId = 0 and EditorInfo.IME_ACTION_NEXT = 5

When I run through the Android soft keyboard its working fine.

  txtQty.setOnEditorActionListener( new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            Log.i("KeyBoard" ,"Inside the Edit Text");
            Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
            Log.i("---actionId---" , actionId);
            Log.i("---event---" , event);
            Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);

Here it's giving EditorInfo.IME_ACTION_NEXT = 5, actionId = 5 and EditorInfo.IME_ACTION_DONE = 6, actionId = 6

But when I run through my soft keyboard it gives EditorInfo.IME_ACTION_NEXT = 5,
actionId = 0
and EditorInfo.IME_ACTION_DONE = 6, actionId = 0.

Why didn't it take the actionId value on my soft keyboard?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一向肩并 2024-12-15 10:28:32

如果你想获得actionid,请尝试以下方式:

在我的项目中,我像这样更改edittext的属性

input type  -----  text
ime options -----  actionDone

,并在java文件中:

  etSearch = (EditText) findViewById(R.id.etSearch);
  etSearch.setOnEditorActionListener(mEditorActionListener);

private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // TODO Auto-generated method stub
        if (actionId == EditorInfo.IME_ACTION_DONE) {
                       //do something
        }
        return false;
    }
};

这样可以获得actionid = 6;

if you wanna got the actionid try this way:

in my project i change the edittext's properties like that

input type  -----  text
ime options -----  actionDone

and in java file:

  etSearch = (EditText) findViewById(R.id.etSearch);
  etSearch.setOnEditorActionListener(mEditorActionListener);

private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // TODO Auto-generated method stub
        if (actionId == EditorInfo.IME_ACTION_DONE) {
                       //do something
        }
        return false;
    }
};

in this way could got the actionid = 6;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文