我有一個EditText
,我使用作爲我的ListView
。我試圖訪問焦點/失去焦點事件,但由於某種原因,它每次焦點都會發射多次。這裏發生了什麼?Android - ListView EditText焦點問題
// in onCreate
// ...
// the footer
View v = getLayoutInflater().inflate(R.layout.comment_edittext, null);
EditText commentEditText = (EditText)v.findViewById(R.id.comment_edittext);
commentEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus)
{
U.log("View: " + v.getClass().getName().toString());
if(hasFocus)
{
U.log("Clicked");
}
else
{
U.log("Un Clicked");
}
}
});
// add the footer
commentListView.addFooterView(v);
// ...
輸出,單點觸摸,這帶來了鍵盤是:
04-11 10:22:17.449: E/004 - X(4576): View: android.widget.EditText
04-11 10:22:17.459: E/004 - X(4576): Clicked
04-11 10:22:17.569: E/004 - X(4576): View: android.widget.EditText
04-11 10:22:17.569: E/004 - X(4576): Un Clicked
04-11 10:22:17.569: E/004 - X(4576): View: android.widget.EditText
04-11 10:22:17.569: E/004 - X(4576): Clicked
04-11 10:22:17.689: E/004 - X(4576): View: android.widget.EditText
04-11 10:22:17.689: E/004 - X(4576): Un Clicked
04-11 10:22:17.709: E/004 - X(4576): View: android.widget.EditText
04-11 10:22:17.709: E/004 - X(4576): Clicked
我可以種理解它調用帶有hasFocus
設置多個事件true
,但爲什麼然後在那裏也false
s,觸發Un Clicked
登錄?
編輯:此外,每當我滾動ListView
上下移動EditText
進出來看,它調用這些事件也是如此。我是否使用了錯誤的偵聽器類型?
我的猜測是你的onCreate方法被多次調用。 – njzk2 2012-04-11 17:06:51