在安卓中有多个文本编辑框

4
我想根据以下图片创建一个输入验证码的文本框。我已经使用了四个编辑框,但我的问题是我无法从一个编辑框移动到另一个编辑框及反之。请帮我解决这个问题。 enter image description here

“将光标从一个EditText移动到另一个EditText”是什么意思? - Paresh Mayani
当用户在编辑文本中输入一个字符/数字时,光标应跳转到下一个编辑文本。 - user853341
2个回答

0
我认为这样做可以满足你的需求:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >


</EditText>
 <EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >


</EditText>
<EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >


</EditText>
<EditText
    android:id="@+id/editText4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >


</EditText>

或者你想在填写完一个EditText后自动跳转到另一个EditText吗?


是的,我想在填写完一个EditText后自动跳转到另一个EditText。 - user853341

0

你说你无法“在两个EditText之间移动光标”,是什么意思?

比如说,当你在一个EditText中输入一个字符/数字时,光标应该跳到下一个EditText吗?

如果是这样的话,尝试使用getFocus()并为EditText实现一个TextWatcher,它有一个回调函数,在每个字母输入后被调用。


我可以在所有EditText中使用相同的TextWatcher吗?如果是这样,我该如何设置光标位置? - user853341
textWatcher 知道是哪个视图/编辑框调用了它,所以只需获取 view.getId() 并创建 switch-case 代码别名 "if (id = 1) edittext2.getfocus(); if (id=2) edittext3.getfocus(); etc."。 - Alone89
如果不起作用,请在此处写下来,这样其他人就可以节省时间知道这不是解决方案;-) 另一方面,如果它起作用了,请别忘记将其标记为最佳答案:)) - Alone89

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接