I want an EditText which creates a DatePicker when is pressed. So I write the following code:
mEditInit = (EditText) findViewById(R.id.date_init);
mE
Default working of EditText
:
On first click it focuses and on second click it handles onClickListener
so you need to disable focus. Then on first click the onClickListener
will handle.
To do that you need to add this android:focusableInTouchMode="false"
attribute to your EditText
. That's it!
Something like this:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:inputType="text" />
Here is what worked for me
Set editable to false
<EditText android:id="@+id/dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Date of Birth"
android:inputType="none"
android:editable="false"
/>
Then add an event listener for OnFocusChange
private View.OnFocusChangeListener onFocusChangeDOB= new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
showDialog(DATE_DIALOG_ID);
}
}
};