在一个框焦点转到第一框后输入字符 [英] focus goto on next box after enter character in first box
问题描述
我要实现我在其中设置小的EditText
输入PIN号码和手机号码的应用程序。每个编辑文本包含1个字符一次。结果现在,当我运行这个程序,我发现,每个盒子我需要给重点每个的EditText
。结果因此,在这种情况下,是第一,然后转到三是输入的字符后,第二次输入字符之后有可能将焦点设置在明年的EditText。结果,请帮我出这个
下面是布局图像。
1。实现TextWatcher上EditTexts
然后当你EDITTEXT文本的长度为1
2。更改专注于其他使用的EditText
呼叫 requestFocus()方法
在其他的EditText ..
code:(这code是你的理解,这可能是对你的情况和你不同的需要)
公共类LoginActivity扩展活动实现TextWatcher
{
。
。
。 editTextUName =(EditText上)findViewById(R.id.edttextusername);
editTextUName.addTextChangedListener(本);
editTextPwd =(EditText上)findViewById(R.id.edttextpassword);
editTextPwd.addTextChangedListener(本);@覆盖
公共无效afterTextChanged(编辑S)
{
如果(s.toString()。长度()== 1)
{
editTextPwd.requestFocus();
}
}
I have to implement an application in which I have set small edittext
for input PIN number and Mobile Number. Each edit text contain 1 character at a time.
Now when I run this app, I found that for each box I need to give focus to each edittext
.
So in this case is it possible to set focus in next edittext after character is entered in first and then goto third after character is entered in second.
so please help me out this
Here is layout image.
1. implements TextWatcher on EditTexts
and then when you get Edittext's text length is 1.
2. Change focus on other EditText using
Call requestFocus()
on the other EditText..
CODE: (This code is for your understanding, It may be different on your case and your need)
public class LoginActivity extends Activity implements TextWatcher
{
.
.
.
editTextUName = (EditText) findViewById(R.id.edttextusername);
editTextUName.addTextChangedListener(this);
editTextPwd = (EditText) findViewById(R.id.edttextpassword);
editTextPwd.addTextChangedListener(this);
@Override
public void afterTextChanged(Editable s)
{
if (s.toString().length() == 1)
{
editTextPwd.requestFocus();
}
}
这篇关于在一个框焦点转到第一框后输入字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!