本文介紹了我怎么知道 EditText 何時失去焦點?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當 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 何時失去焦點?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!