当 EditText
失去焦点时,我需要捕捉,我已经搜索了其他问题,但没有找到答案.
I need to catch when an EditText
loses focus, I've searched other questions but I didn't find an answer.
我像这样使用OnFocusChangeListener
OnFocusChangeListener foco = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
}
};
但是,它对我不起作用.
But, it doesn't work for me.
实现setOnFocusChangeListener
的onFocusChange
,hasFocus有个布尔参数.如果这是错误的,您就失去了对另一个控件的关注.
Implement onFocusChange
of setOnFocusChangeListener
and there's a boolean parameter for hasFocus. When this is false, you've lost focus to another control.
EditText txtEdit = (EditText) findViewById(R.id.edittxt);
txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// code to execute when EditText loses focus
}
}
});
这篇关于我怎么知道 EditText 何时失去焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!