Android将光标从一个EditText移到另一个? [英] Android Move cursor from one EditText to another one?

查看:412
本文介绍了Android将光标从一个EditText移到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这类问题问了很多次,但仍然没有人给出完美的答案.

I know these type of question asked many time .but still nobody gave perfect answer for that.

我有问题:

我想从 EditText1 **移至另一个** EditText2 . 我已经检测到editText1,但是如何将光标移至editText2.?

I want to move from EditText1 ** to another **EditText2 . I had already detect to editText1 but how to move cursor to editText2.?

简而言之,我不得不将光标位置直接从一个editText1移到另一个EditText2.

In short I had to move my cursor position from one editText1 to another EditText2 directly.

推荐答案

我遇到了此类问题,并找到了以下解决方案.

I faced this type of issue and found the solution as below.

这里我有两个editText,

Here I have two editText ,

如果我按"a",则光标将移至下一步.我使用下面的代码来做到这一点.

if I press "a", my cursor will move to next step . I used below code for doing it.

 final EditText editText = (EditText) findViewById(R.id.editText1);

       editText.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v , int keyCode , KeyEvent event) {

                  EditText editText2 = (EditText) findViewById(R.id.editText2);

                // TODO Auto-generated method stub
                if (keyCode == event.KEYCODE_A) {

                    Selection.setSelection((Editable) editText2.getText(),editText.getSelectionStart());
                    editText2.requestFocus();
                }

                return true;
            }
        });

如果您遇到任何错误,请告诉我. 如果我的回答对您有帮助,请接受并评分.

let me know if you are facing any error regarding this. If my answer is helpful to you please accept it and rate to upvote.

这篇关于Android将光标从一个EditText移到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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