OnClickListener in TextInoutEditText wrapped around TextInputLayout

I have a TextInputEditText wrapped around a TextInputLayout , as Google recommends: https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

However, my TextInputEditText has an OnClickListener installed on it, so when a user receives a response, the user can pop up a DatePickerDialog.
My problem is that, in fact, when you first touch nothing happens except for the hint label to move over the TextInputEditText. A second press displays DatePickerDialog.

How can I get this DatePickerDialog to display on the first touch?
Setting onClickListener to TextInutLayout instead of TextInputEditText does not work. Does anyone have an idea?

+4
source share
1 answer

Opening the calendar only with the second press occurs because you are using edittext. The first click, your text will receive focus. then the second click only calls onClickListener.

If you do not want to edit the date set manually (using the keyboard), then why not use the TextView to display the selected date ?.

Show calendar on first click:

EditText , onFocusChangeListner editText onClickListner.

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus) {
           // Show your calender here 
        } else {
           // Hide your calender here
        }
    }
});
+5

Source: https://habr.com/ru/post/1661143/


All Articles