如何让 OnFocusChangeListener 在设备旋转后再次收听?

How do I get OnFocusChangeListener to listen again after Device Rotation?

我有一个 EditText,它在获得焦点或被单击时启动 DatePickerDialog 片段。它工作正常。但是,在设备旋转后,OnFocus 侦听器不再启动片段。焦点移动到 EditText 行,但光标只是闪烁,对话框没有启动。有任何想法吗?我需要在 onResume 中添加一些额外的代码吗?

Activity 文件:

fEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {  
       if (hasFocus && (fEditText.getText().length() == 0) && (savedInstanceState  == null)) {
        DatePickerFragment newFragment = new DatePickerFragment();
        newFragment.show(getSupportFragmentManager(), "datePicker");
       }
    }
});

布局文件:

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".Activity">

<android.support.design.widget.TextInputLayout
    android:id="@+id/DueDate_text_input_layout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"  >

<com.example...EditText
    android:id="@+id/FEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="date"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#FFFFFF" >

</com.example...EditText>
</android.support.design.widget.TextInputLayout>
...

onResume() 中尝试以下,而不是 ActivityonCreate()fragment

onCreateView
@Override
public void onResume() {
    super.onResume();         

    fEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {  
       if (hasFocus && (fEditText.getText().length() == 0) && (savedInstanceState  == null)) {
        DatePickerFragment newFragment = new DatePickerFragment();
        newFragment.show(getSupportFragmentManager(), "datePicker");
       }
    }
  });    
}