Код ниже был сделан, чтобы открыть всплывающее окно календаря при нажатии на текст редактирования дня рождения. Это работает, проблема в том, что когда я нажимаю другой текст редактирования после нажатия на текст редактирования дня рождения (например, текст редактирования страны), и снова открывается всплывающее окно календаря. Почему это происходит?
Класс Java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
prepareCalendar();
}
public void prepareCalendar() {
date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
findViewById(R.id.birthday).setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
new DatePickerDialog(EditActivity.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
}
private void updateLabel() {
String myFormat = "dd/MM/yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(myFormat, new Locale("pt", "BR"));
birthday.setText(dateFormat.format(myCalendar.getTime()));
}
XML:
<TextView
android:id="@+id/birthdayLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/birthday"
android:importantForAutofill="no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:inputType="date"
android:focusable="true"/>
<TextView
android:id="@+id/countryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/country"
android:importantForAutofill="no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"/>