I have a view with some input fields, one of those is a TextInputEditText
with a datepicker
associated which shows up when the field is selected. The problem is that at the first tap, the TextInputEditText
field gets the focus and it is required a second tap do show the datepicker
.
This is how the field is defined
<android.support.design.widget.TextInputLayout
android:id="@+id/wExpiresAt"
style="@style/AppTheme.TextInputLayout"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:errorTextAppearance="@style/AppTheme.Text.ErrorText"
app:hintTextAppearance="@style/AppTheme.Text.HintText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/wMessage">
<android.support.design.widget.TextInputEditText
android:id="@+id/tvExpiresAt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/tv_pick_date_ph"
android:imeOptions="actionNext"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
While inside the activity:
val mExpiresAt: TextInputEditText = findViewById(R.id.tvExpiresAt)
mExpiresAt!!.setOnClickListener {
val cal = Calendar.getInstance()
val year = cal.get(Calendar.YEAR)
val month = cal.get(Calendar.MONTH)
val day = cal.get(Calendar.DAY_OF_MONTH)
val dialog = DatePickerDialog(
this@NewMessageActivity,
android.R.style.Theme_Material_Light_Dialog_MinWidth,
mDateSetListener,
year, month, day)
dialog.show()
}
My guess is that the problem is caused by the TextInputLayout
which wraps the TextInputEditText
, the first tap fires the animation which moves the hint string from the text field to its top and gives the focus to the field itself, the second tap fires the listener associated to the text field and the datepicker
appears. How can I get all the events on the first tap?