如何自动移动到Android的下一个编辑的文本 [英] How to automatically move to the next edit text in android
问题描述
我有一行几编辑文本框。后在第一字符的特定数目的用户类型我想自动移动到下一个编辑文本。我如何做到这一点?
I have a couple of edit text boxes on a single line. After the user types in a specific number of characters in the first I want to automatically move to the next edit text. How do I achieve this?
推荐答案
您可以使用文本看守
类实现这一目标,然后将焦点设置在下次的EditText
在TextWatcher的 OnTextChanged()
方法。
You can achieve this by using the Text Watcher
class and then set the focus on the next EditText
in the OnTextChanged()
method of the TextWatcher.
在你的情况,因为你有两个编辑文本,比如 ET1
和 ET2
。你可以试试下面的code: -
In your case, since you have two Edit Texts, say et1
and et2
. You can try out the following code:-
et1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,int before, int count)
{
// TODO Auto-generated method stub
if(et1.getText().toString().length()==size) //size as per your requirement
{
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
我没有检查出Ç自己的$ C $,但我希望这会帮助你解决你的问题。
I have not checked out the code myself, but I hope this will help you solve your problem.
这篇关于如何自动移动到Android的下一个编辑的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!