OnClickListener in TextInputEditText wrapped around TextInputLayout

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

However, my TextInputEditText has an OnClickListener set on it so when it gets tapped by the User, a DatePickerDialog can popup. My issue is that in fact, on the first tap nothing happens apart from the hint label to move above the TextInputEditText. On second tap, the DatePickerDialog is shown.

How could I get that DatePickerDialog to show up on first tap? Setting the onClickListener on the TextInutLayout instead of the TextInputEditText does not work. Anyone has an idea?


The calendar opening only on the second click is because you are using an edittext. On the first click, your Edit Text will get focus. then the second click only calls the onClickListener.

If you are not looking forward to edit the date set manually (using keyboard), then why not using a TextView to display the selected Date?.

Show Calendar on First Click :

If you need to use EditText and load the calender in the first click, then try setting an onFocusChangeListner to the editText instead of onClickListner.

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

TextInputLayout, How could I get that DatePickerDialog to show up on first tap? Setting the onClickListener on the TextInutLayout instead of the TextInputEditText does not work. I faced the same issue and my solution was to use the setOnFocusChangeListener on the EditText inside the TextInputLayout. This is an example using ButterKnife . The Layout:


Set the attribute android:focusableInTouchMode to false, like this:

android:focusableInTouchMode="false"

in your edittext xml code. For more information, visit here

Making textinputlayout uneditable and setting click event on it, around TextInputLayout. 发表于2019-9-23 | | 暂无分类. I have got a TextInputEditText wrapped around a TextInputLayout, as Google recommends to do:� Always getting this warning TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead. and not finishing Activity for First time. On Second time not getting an warning and activity finishing perfectly. activity_login.xml LoginActivity.java public class Log


I answered the linked question with an improved solution that does not affect keyboard navigation but still allows you to have the desired focus behaviour.

See https://stackoverflow.com/a/62875800/9901599, but the crux of it is to not set any focus-related XML attributes, and do this in code:

editText.setOnFocusChangeListener { view, isFocused ->
    if (view.isInTouchMode && isFocused) {
        view.performClick()  // picks up first tap
    }
}
editText.setOnClickListener {
    showDatePicker() // the actual thing you want to do
}

TextInputEditText中的OnClickListener包装在TextInputLayout周围, Layout which wraps a TextInputEditText , EditText , or descendant to show OnClickListener , an TextInputLayout. Set up the end icon mode. In this video we will learn, how to use the TextInputLayout together with the TextInputEditText widget, to create an EditText with advanced features like a floating label for the hint, a character


[TextInputEditText] Does not detect click event � Issue #814 � material , android textinputedittext onclick listener After Setting up this image application user an set on click event on so Use another add source directly block and To display floating label in EditText, TextInputLayout needs to wrapped the EditText. Attempting to give an edit text an onclicklistener whilst using focusable=false, clickable=true, editable=false does not trigger onclick events unless you click outside of the region of the EditText (such as the label above the edit text


Android Design Support Library: TextInputLayout, TextInputEditText does not detect the click event when it is used to write a debug message in Logcat (or any other TextInputLayout android:layout_width=" match_parent" The onclicklistener is only triggered if the text field has focus (so it triggers first Sign up for free to join this conversation on GitHub. TextInputLayout is a new element introduced in Design Support library to display the floating label in EditText. Learn it with example in Android Studio.


Build a better UI with the Material Design Components library , As said before, TextInputLayout wraps the EditText so that it controls the EditText behaviour. this EditText, this one has to be wrapped by TextInputLayout so that we can have the floating label. public void onClick(View v) {. How to add on click event function above EditText icon image in android. Setting up onclicklistener() function is too difficult because there are lot’s of way to add click functionality above drawable image inside EditText, so here is the best solution to make your drawable icon works as real buttons.