我有EditText,我将ListView作为页脚View使用。我试图访问焦点/失去焦点事件,但由于某种原因,它每次焦点都会发射多次。这里发生了什么?
// 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的多个事件,但为什么还有falses,触发了Un Clicked日志?
编辑:此外,无论何时上下滚动ListView,将EditText移入和移出视图,它都会调用这些事件。我是否使用了错误的侦听器类型?