我的 Activity 上有 2 个 EditText,并将 maxLength
设置为 5.
I have 2 EditText's on my Activity and set the maxLength
to 5.
现在我想将焦点设置到editText2
,如果在editView1
中达到5的长度...
Now I want to set the focus to editText2
, if the length of 5 is reached in editView1
...
我试过了:
editView1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(editView1.getText().length() == 5)
editView2.requestFocus();
return false;
}
});
但它不会工作..
这可行
final EditText editText1 = (EditText) findViewById(R.id.editText1);
final EditText editText2 = (EditText) findViewById(R.id.editText2);
editText1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(editText1.getText().length() == 5)
editText2.requestFocus();
return false;
}
});
这篇关于将焦点更改为 EditText Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!