我有一个editText,如:
<EditText
android:id="@+id/card_summary_name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:digits="0123456789qwertzuiopasdfghjklyxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
android:imeOptions="actionDone"
android:inputType="text"
android:singleLine="true" />
现在,当用户在键盘上按下完成按钮时,editText将失去焦点,并执行操作:
mCardNameEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE)
{
mCardNameEditText.clearFocus();
return true;
}
return false;
}
});
mCardNameEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
performAnAction();
}
}
});
现在发生了使用clearFocus(),调用performAction(),但editText仍然有光标闪烁,所以当我关闭包含editText的片段时,它再次失去焦点并再次调用performAction。我该如何解决?