When an EditText
line in the UI gains focus, a DatePickerFragment
launches for the user to enter a date.
On orientation change, if the EditText
line has focus and a previously entered date (so that length() > 0
) I don't want the fragment to automatically show.
Is there a way to modify or add code so that if the Activity is newly created and the EditText
line has focus it won't automatically launch the DatePickerFragment
?
Would it be a good idea to do something in onResume()
?
Or do something with savedInstanceState()
and !=null
?
public class Activity extends AppCompatActivity {
...
EditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
...
if (hasFocus && (EditText.getText().length() == 0)) {
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
else if (hasFocus && (EditText.getText().length() > 0)) {
...
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
}
});
}